What are structs in Solidity?

Structs “provide a way of defining new types”.

Structs have fields, as well as methods. They are similar to objects, except that objects do not have methods, while structs do.

Let’s look at a very simple struct Code Source:[Solidity Docs][http://solidity.readthedocs.io/en/develop/types.html#structs]

struct Funder {
        address addr;
        uint amount;

This above code example defines a struct of “Funder” to have both an address named “addr” and a unit integer named “amount”. This is part of a struct in an example contract found in a sample crowdfunding contract for the funder.

Structs cannot contain members of their own type. In other words, a struct cannot contain a struct. This is because the size of the struct must be finite, while nesting structs does not lead to them being finite.

Published 24 Nov 2018

founder && full stack && ethereum developer.
Max Goodman on Twitter