Structs

Learn how to use structs in Solidity.

So far, we’re only using built-in Solidity types in our smart contracts. But with Solidity, we can also define composite types containing multiple fields in one variable. To do this, we need to use structs, a feature we'll learn about in this lesson.

We'll first see how we can define and use structs. Then, we'll add a feature to our smart contract that will allow us to track who owns each name in our registry. An owner of a name will then have some extra privileges that we'll implement later in this lesson.

Structs in Solidity

Structs in Solidity allow for the creation of a new type that packs together multiple fields in one variable. It's somewhat similar to classes in other programming languages, but structs in Solidity don't have methods and don’t support inheritance.

Get hands-on with 1200+ tech skills courses.