It seems that Solidity can only handle mappings to elementary data types or structs. Is there some mapping that can handle arbitrary (dynamic) types for the values? Something like:

mapping(string => any) foo;

I have no clue how this would work.

1 Answer 1


You can map to a struct which could be designed to suit your purpose, e.g,

struct MyType {
    uint someInt;
    bytes[] someBytes;

mapping (string => MyType) foo;

But if you mean any to simply be untyped, then no you can't do that. You could perhaps use a bytes[] array and run the element through some manual type conversion functions which sounds much more complicated than simply designing your contract around strict types.

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.