Solidity Tutorial: all about Structs

Jean Cvllr
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

  1. Basic of Structs
  2. How to define a new Struct type?
  3. How to declare a new variable of type Struct?
  4. Struct members types
  5. Structs + Mappings and Arrays = the good mix
  6. Storage, Memory and Calldata with Structs
  7. The ‘delete’ keyword
  8. 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;
}

2. How to define a new…

--

--