Schemas
Sometimes your contract needs more than simple values. You might want to organize related data into a single shape, or define a fixed set of choices that never changes.
Two Types of
A
For example, a “Member”
An
For example, a “Status”
Try It Yourself
The interactive panel below works just like the real editor. Complete each task to explore both types of
Define a set of fixed choices your contract can pick from.
Options Lists
A fixed set of named options to choose from
What You Learned
By completing the tasks above, you explored two ways to define custom
- An
enum (like “Status”): perfect for situations where only a few specific choices make sense, such as contract states or membership tiers - A
struct (like “Member”): great for bundling related fields together, so you can treat them as a single unit throughout your contract - Adding fields to a
struct : each field has a name and a type, letting you describe exactly what shape your data takes
These
Key Concepts
struct s: Custom data shapes that bundle related fields together. Each field has a name and a type (like Number, Text, or Wallet Address).enum s: A fixed set of named choices your contract can pick from. The values never change after you define them.- Fields: The individual pieces of data inside a
struct . Each field has a name (what it’s called) and a type (what kind of data it holds). - Reusability: Once defined,
struct s andenum s can be used anywhere in your contract, just like built-in types such as Number or Text.
How hard was this?