I would like a simple address book referencing a user name to an ethereum address like,

mapping (string => address) addressOf;

Unfortunately I can't access that mapping as a public call, as strings are dynamically-sized.

Is there any existing solution or work around, to access a string key mapping without .sendTransaction?

1 Answer 1


You can use bytes32 like this:

contract NameRegistry {
    mapping(bytes32 => address) addressBook;

    function set(string a, address b){
        addressBook[sha3(a)] = b;

    function get(string a) constant returns(address){
        return addressBook[sha3(a)];

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.