Member-only story
Solidity Tutorial: all about Enums
9 min readAug 1, 2019
The word Enum in Solidity stands for Enumerable. They are user defined type that contain human readable names for a set of constants, called member. The data representation for an enum is the same as the one in the C language.
Table of Contents
- How and When to create Enums?
- Enums explained with a card deck
- Accessing an Enum value
- Modifying an enum value
- Transition through different Enums values
- Using Enums with modifiers
- Represent Enums as Strings
- Using Hash Functions with Enums
- Use Enums as a KeyType in Mappings
- What you can’t do with Enums in Solidity?
1. How and When to create Enums?
A classical example of an Enum would be a deck of card, to represent:
> The suits (Spades, Clubs, Diamonds, Hearts).
> The ranks / values (2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, King, Queen, Ace).
enum Value { Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack…