0

I would like to create a mapping with a struct inside as key

struct MyMap { 
   bytes32 data1; 
   address data2; 
   string  data3;
} 
mapping(MyMap => bool) public currentMap;

but i am getting this error:

Only elementary types, user defined value types, contract types or enums are allowed as mapping keys.

1 Answer 1

1

Structs cannot be used as key in mappings

from the doc:

mapping(_KeyType => _ValueType)

The _KeyType can be any built-in value type, bytes, string, or any contract or enum type. Other user-defined or complex types, such as mappings, structs or array types are not allowed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.