12 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 - &...
Alex Coventry's user avatar
5 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 ...
Rob Hitchens's user avatar
  • 55.2k
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, ...
goodvibration's user avatar
3 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.
Chris_77's user avatar
  • 141
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 ...
Rob Hitchens's user avatar
  • 55.2k
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 "...
Patrick Collins's user avatar
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 ...
Ahmed Ihsan Tawfeeq's user avatar
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'...
ceseshi's user avatar
  • 740
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 ...
EthanOK's user avatar
  • 451
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('...
Antonio Carito's user avatar
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 ...
Kelvin Chelenje's user avatar
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 ...
faher ali's user avatar
  • 124
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 ...
Brendon Rofe's user avatar
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 ...
Munkh-Od Ganzorigt's user avatar
1 vote

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.)
Aurel's user avatar
  • 71
1 vote

Possible to get enum length / count in solidity contract?

Yes, since enums are 0-indexed the length is: type(ActionChoices).max + 1
user3680688's user avatar
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 ...
Andrew's user avatar
  • 11
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 ...
Rob Hitchens's user avatar
  • 55.2k
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.
Mikko Ohtamaa's user avatar
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;...
mzaidi's user avatar
  • 992
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 ...
Sergi Juanati's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible