Solidity Tutorial: all about Structs
7 min readAug 1, 2019
Structs are a way to define new custom types in Solidity. The Solidity documentation define them as “objects with no functionalities”, however, they are more than that.
Like in C, structs in Solidity are a collection of variables (that can be of different types) under a single name.
This enable you to group many variables of multiple types into one user defined type.
Table of Contents
- Basic of Structs
- How to define a new Struct type?
- How to declare a new variable of type Struct?
- Struct members types
- Structs + Mappings and Arrays = the good mix
- Storage, Memory and Calldata with Structs
- The ‘delete’ keyword
- What you can’t do with Structs?
1. Basic of Structs
struct Account {
uint balance;
uint dailylimit;
}
We can treat a struct
like a value type such that they can be used within arrays and mappings.
Account my_account = Account(0, 10);function setBalance(uint new_balance) public {
my_account.balance = new_balance;
}