13
votes
Accepted
What is a function's function signature if it uses a custom type? (Stuct, enum, etc)
You'll need to know the functions parameters elementary type and use that.
For an enum, the type is uint8.
You can determine this using the --abi option to solc (or other compilers):
❯ solc --abi - &...
6
votes
Accepted
Possible to get enum length / count in solidity contract?
enum is an integer, so the integer value of the last item plus 1 is the length.
You can also make the function argument typesafe.
function move (ActionChoices choice) ...
That will constrain the ...
4
votes
Accepted
ethers.js how to call overloaded function with enum argument
Ok, I found the answer - enums are treated as uint8 internally by solidity, so myContract["overloaded(uint8)"](0) works. Leaving this here in case it helps anyone.
3
votes
Accepted
What size is an enum member inside of a struct
Yes, it depends on the number of members in the enum.
See the official documentation:
pragma solidity >=0.4.16 <0.6.0;
contract test {
enum ActionChoices { GoLeft, GoRight, GoStraight, ...
2
votes
interacting with an enum as an interface in other contract
I fiddled and cleaned up a bit so the Type is declared in one place only (DRY).
You can convert an enum to a number but you have to go through intermediary conversions to get there. Since there are ...
2
votes
Possible to get enum length / count in solidity contract?
uint(type(ActionChoices).max)+1
Otherwise, you will get error.
(Also as reminder, function using ActionChoices as parameter will accept uint8 as parameter.)
2
votes
Possible to get enum length / count in solidity contract?
Yes, since enums are 0-indexed the length is:
type(ActionChoices).max + 1
2
votes
What is a function's function signature if it uses a custom type? (Stuct, enum, etc)
You'll need to know the functions elementary type and use that.
For an enum, the type is uint8. You can often find this information from the compiler information in the ABI.
In cast:
cast sig "...
2
votes
Accepted
How to Use Subgraph Enums in the Mapping?
You cannot import enums into mappings from the generated schema. Instead, you are expected to use the string representation of the enum value to set an enum field of an entity, just as mentioned in ...
1
vote
How to access a mapping from another contract with enums
First, you cannot directly read a variable from another contract, even if it's public. You need to use the public getter personnelList(), and in this case, wrap it in the struct to be able to read it'...
1
vote
How to access a mapping from another contract with enums
mapping (uint256 => TrainedPerson) public personnelList;
Because the variable personnelList is declared as public, there will be a personnelList(uint256) get function. The return value of this ...
1
vote
How to access a mapping from another contract with enums
In the latest version of Solidity, for calling getter() function about public variable you must use round brackets [()].
In your case you must use this statement:
contractName.mappingName('...
1
vote
Encoding ENUM data type in struct for EIP712
The issue could be with the encoding of the data that is being signed.
In your Solidity code, you have defined the OrderType enum as BUY and SELL. However, in your JavaScript code, you are using uint8 ...
1
vote
I want to get retuen enum return value in string ...but its showing expected only uint256
unable to understand your problem but as @brendon Richards write code, this is quite clear example of usage of enum. because in enum return, it always return number but it depends on you how you use ...
1
vote
I want to get retuen enum return value in string ...but its showing expected only uint256
To be honest, you question isn't very clear, and I'm not exactly sure what you're asking, but I have written a basic smart contract, which I hope can help.
// SPDX-License-Identifier: MIT
pragma ...
1
vote
Accepted
How can I use a library to create a common enum and struct between two contracts?
It seems like you forgot to reference from the library like this Library.Areas , which is why it isn't working and calling out an error.
I found an example on the official solidity doc that shows you ...
1
vote
interacting with an enum as an interface in other contract
Solidity does not allow implicit conversion from A.NUM to interEnum.SIDE, nor will it allow an explicit conversion like b.bEnum(SIDE(num)). Since your b.bEnum() takes SIDE as a param, you should pass ...
1
vote
Can I write a function to edit an enum?
As Mikko says, the short answer is "no."
To make the list dynamic, you would have to use storage and implement functions to add, update, delete options. This will increase the gas cost at ...
1
vote
Can I write a function to edit an enum?
Enums are constants so you can't.
Regardless of programming language, constants are evaluated compile time and cannot be changed run time.
1
vote
Pass enum value in mapping
Your struct is expecting an array of Category Category[] category; and you are passing just a single enum value. If you just have to pass a single value change the struct variable to Category category;...
1
vote
If I pass an enum as a parameter does it get stored in the blockchain?
When you declare an enum, each element is assigned an integer sequentially. In your case:
rock = 0
paper = 1
scissors = 2
Not sure why you want to pass this enum in the constructor, but if you want ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
enum × 22solidity × 15
library × 4
mapping × 3
ethers.js × 3
contract-development × 2
struct × 2
hardhat × 2
remix × 1
evm × 1
storage × 1
erc-721 × 1
gas-price × 1
nft × 1
memory × 1
interfaces × 1
solidity-0.7.x × 1
eip712 × 1
function-selector × 1
function × 1
the-graph × 1
vrf × 1
subgraph × 1
data × 1
graphql × 1