Member-only story

Solidity Tutorial: all about Enums

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

  1. How and When to create Enums?
  2. Enums explained with a card deck
  3. Accessing an Enum value
  4. Modifying an enum value
  5. Transition through different Enums values
  6. Using Enums with modifiers
  7. Represent Enums as Strings
  8. Using Hash Functions with Enums
  9. Use Enums as a KeyType in Mappings
  10. 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…

--

--

Jean Cvllr
Jean Cvllr

Written by Jean Cvllr

Smart Contract engineer at @LUKSO. Full Stack Developer. https://github.com/CJ42

Responses (4)