Solidity function how to return custom datatype ?

ILethereumILethereum Member Posts: 34
Let's say I have a custom datatype "mapping (bytes32 => address) public users"; Now I would like to write a function which returns the users object.

I tried "function getAddress(bytes32 name) returns (users user) {
return users;
}" no luck. "Type error: Invalid type name". Any help is greatly appreciated.


  • SmithgiftSmithgift Member Posts: 64
    The mapping keyword doesn't create a new type, it creates a single variable which can be used like a python dict, where the keys are the type before the => and the values are the type after the =>.

    If you're trying to access the users variable from within solidity, use
    users[name] to get the address of the user named name, or users[name] = someaddress to assign someaddress to the user named name.

    If you're trying to access the users variable from JavaScript, use: contractName.users(name) where contractName is the name of your contract. As long as users is public, this just works. Unfortunately, there's no automatic way to assign from javascript.
  • ILethereumILethereum Member Posts: 34
    Thanks Smith! That helps.
Sign In or Register to comment.