Answers for "enums in solidity"

2

enums in solidity

contract MyEnums {
    
    enum Rarity {
        original, // 0
        rare, // 1
        super_rare // 2
    }
    
    Rarity public rarity;
    
    constructor() {
        rarity = Rarity.rare;
    }
    
    function makeSuperRare() public {
        rarity = Rarity.super_rare;
    }
}
Posted by: Guest on May-02-2022
1

solidity enum

enum EnumType { Value1, Value2, Value3 }

EnumType MyEnum;
MyEnum = EnumType.Value1;

// uint8(EnumType.Value1) => 0
// uint8(EnumType.Value2) => 1
// uint8(EnumType.Value3) => 2
Posted by: Guest on April-22-2022

Browse Popular Code Answers by Language