Questions tagged [enum]
A data type consisting of a set of named values called elements, members or enumerators of the type.
23
questions
0
votes
0
answers
9
views
Does Brownie support structs and enums?
Brownie is a seemingly popular framework for testing smart contracts (both solidity and vyper) in python.
I've just gotten started with brownie and my first few tests are working. However, I can't ...
0
votes
3
answers
44
views
How to access a mapping from another contract with enums
The second contract needs to check the mapping in the first contract to see if the person finished the required course. I checked a few old threads but they said it wasn't possibly with that version ...
0
votes
1
answer
219
views
Encoding ENUM data type in struct for EIP712
I have a struct.
struct Order {
uint256 price;
uint256 quantity;
OrderType orderType;
}
enum OrderType {
BUY,
SELL
}
Question is, how should I ...
1
vote
0
answers
22
views
I can't get API3 QRNG to select a random enum value and mint an NFT based on this enum choice
I tried to make a contract that mints a token from an enum of options https://gist.github.com/ChristianOConnor/0ae15b021521c9583dde6c3cc782d4d3. This code fails at every turn. I started with the code ...
1
vote
1
answer
306
views
How to Use Subgraph Enums in the Mapping?
Subgraph documentation mentions enums but does not show how to use them in mappings.
I tried to import it from the generated schema, along with other type definitions, but compiler gives error:
...
0
votes
2
answers
121
views
I want to get retuen enum return value in string ...but its showing expected only uint256
{
return studentStructs [user].books[raw];
}
// Type string memory is not implicitly convertible to expected type uint256.
5
votes
2
answers
896
views
What is a function's function signature if it uses a custom type? (Stuct, enum, etc)
I have the following Enum that is an input to a function
enum Cat {
Tabby,
Rascal,
Cool
}
function hiMom(Cat myCat) public {
What is the function signature of hiMom(Cat)?
0
votes
0
answers
27
views
Why am I not able to call a pure function accessing an enum from a library?
I'm working on a token-gated NFT distribution site. I've divided up the 256 bits of the token id & I'm using various parts to represent different aspects of a permissioning system.
Central to the ...
0
votes
1
answer
807
views
ethers.js how to call overloaded function with enum argument
Ethers generally doesn't let you call an overloaded function like this contract.overloaded(1), but it does let you call it with a fully qualified function name like this contract["overloaded(uint)...
0
votes
1
answer
103
views
Solidity return enum in library
library MyLib {
enum MyEnum {
A, B
}
function f() public pure returns (MyEnum){
return MyEnum.A;
}
}
I want to return the enum in library.
It is deployed as well, but ...
0
votes
1
answer
457
views
Using Enum to assign a value
im new to Solidity.
I was wondering if it is possible to do something like this in Solidity using enum.
enum Menu {
Burger,
Pizza,
Fries
}
uint price; // storing different prices of different items ...
0
votes
1
answer
122
views
Does it make a difference using multiple setter functions vs a single generic one?
Let's say I have an enum and set the default:
enum Status {
INACTIVE,
FAIL,
SUCCESS,
PENDING
}
Status public myStatus = Status.INACTIVE;
I'm wondering if one approach to updating ...
1
vote
0
answers
17
views
How to make Enums scalable? [duplicate]
Let's say that I have a contract Games.sol containing an enum with multiple games.
enum { TicTacToe, PacMan, Chess }
This enum is currently imported from a library and I think that it's immutable, so ...
0
votes
1
answer
344
views
How can I use a library to create a common enum and struct between two contracts?
Here is what I'm trying to do by using a common enum and struct between two contracts:
Library Code:
pragma solidity ^0.8.7;
library Library {
enum Areas {
Burrow, School, Forest, Mine, DeepMine, ...
1
vote
2
answers
664
views
interacting with an enum as an interface in other contract
having this issue of using enum as interface in other contract:
will appreciate your help...
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.9;
interface interEnum {
enum SIDE {
...
1
vote
0
answers
508
views
Hardhat ethers fail to deserialise enum output of a function
I think @nomiclabs/hardhat-ethers fails to manage Enum type of output of a contract when testing it locally.
solidity version 0.8.7
hardhat version 2.6.4
Contract.sol
contract Contract {
enum E {
...
1
vote
0
answers
114
views
Cannot return enum data type?
I have the below enums:
// ENUMS
enum StateType {
ItemAvailable,
OfferPlaced,
Accepted
}
And initialized the below variable State with type StateType:
...
2
votes
2
answers
539
views
Can I write a function to edit an enum?
I have an enum with certain predefined data.
If at a later date, I have to add or push in more choices , can I edit the enum using some function ?
enum ActionChoices { GoLeft, GoRight, GoStraight, ...
0
votes
2
answers
438
views
Pass enum value in mapping
I am trying to pass a default value in solidity but get the following error:
"Invalid implicit conversion from enum tlb.Category to enum tlb.Category[] memory requested"
Does anybody have an ...
0
votes
1
answer
2k
views
If I pass an enum as a parameter does it get stored in the blockchain?
I'm developing a Rock/Paper/Scissors Smart Contract (with a Commit-Reveal scheme).
I have this enum: enum Move {rock, paper, scissors}
I want to pass it to a function, without storing it to the ...
1
vote
0
answers
126
views
Mapping shared between contracts
I have enums that I use in many contracts of one project. Sometimes, they need to be mapped to a uint256. Their uint256 values do not relate to their positions in the enum list, so I can't just cast ...
5
votes
1
answer
2k
views
What size is an enum member inside of a struct
Let's consider the following code:
pragma solidity ^0.4.18;
contract Test {
enum EnumTest {
Test0,
Test1
}
struct StructTest {
EnumTest Foo;
uint256 Bar;
}
}
Not taking ...
2
votes
3
answers
2k
views
Possible to get enum length / count in solidity contract?
Is it possible to access the length of an enum in solidity?
E.g.
pragma solidity >=0.4.16 <0.6.0;
contract test {
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
function ...