Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

Custom types for constants with enum

Like other languages such as C++ and Java, Solidity supports enumerations. Enums can be used to create a custom data type with a fixed set of constant values. Enums will have integer values assigned, starting from 0 and ascending to the number of states defined in enum. Enums in Solidity adopts to uintX data types starting from uint8 up to uint256. According to the number of values present in enum, compiler chooses the data type to be used. For example, when having 1 - 255 number of values defined in an enum would use uint8, however, it will use uint16 when a few more than 255 values are used.

As shown in the example code here, by default, the status variable will be set to 0:

contract LoanStruct {    //Enum ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content