Need an explanation on enum
#6700
Replies: 1 comment 1 reply
-
Hello @EddiePumpin An enum (short for "enumeration") in Solidity is a user-defined type that consists of a set of named values. The RaffleState enum has two possible values: OPEN - Represented by 0 These values are used to manage the state of the raffle, ensuring that certain actions can only be performed when the contract is in the correct state. So to sum up it is just custom type created by us you can add more types to define various things like states in contract or input type for Governor votes for example where you have 3 types of votes (FOR - 0, AGAINST - 1, ABSTAIN - 2). It is up to you how many you want to create and when to use which type to track either parameter type or state or whatever use case you find. |
Beta Was this translation helpful? Give feedback.
-
Please, I need explanation on
RaffleState
. I don't understand how it works.`pragma solidity ^0.8.20;
import "@chainlink/contracts/src/v0.8/vrf/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/automation/interfaces/AutomationCompatibleInterface.sol";
error Raffle__NotEnoughETHEntered();
error Raffle__TransferFailed();
contract Raffle is VRFConsumerBaseV2, AutomationCompatibleInterface { // The is keyword in Solidity is used for inheritance, meaning the Raffle contract is inheriting from other contracts or interfaces.
/* Type declaration */
enum RaffleState { // enums can be used to create custom types with a finite set of 'constant values'. By default, OPEN is set to 0 while CALCULATING is set to 1
OPEN,
CALCULATING
}
`
Beta Was this translation helpful? Give feedback.
All reactions