If I have someone's signature and I want to use it in a mapping, is there a way to have it serve as the key in that mapping?

Would I need to use mapping (string => uint), or mapping (bytes32 => uint), or would I first need to hash the signature?

1 Answer 1


Using string or bytes (not bytes32) will work in the most recent version of solidity, but using the hash is more elegant as your mapping key will be 32 bytes exactly and then you can use mapping(bytes32 => uint).

Hope this helps

  • I'm thinking about gas considerations here, as hashing is costly (is it not)? Would you still recommend that if I were accessing (storing) to this mapping frequently? Jun 10, 2018 at 13:24
  • Is not, taking the hash (keccak256) of a bytes variable of length 64 cost about 900 gas. See this question for the prices of keccak256 and other hash functions
    – Jaime
    Jun 10, 2018 at 13:34

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.