I'm trying to store the sha3 hash of a string in a struct.

The problem is that its size exceeds what fits into a bytes32 type. As such, the alternative would be to have it in a bytes[] or string[]. The problem here is then that it can't be easily returned from a function.

One option would be to split the hash in two and save it like

struct hash {
    bytes32 hash1;
    bytes32 hash2;

This looks a bit bad though, I think.

Is there a common workaround for this issue?

  • Are you creating sha3 hash in contract using solidity ?
    – Rangesh
    Sep 13, 2017 at 10:31
  • No, outside the contract in a node js app.
    – mcansado
    Sep 13, 2017 at 10:31
  • I would suggest you to stick with solidity or web3 for generating hashes (sha3(x) in solidity / web3.sha3(x) which both fits into byte32) . And what is the length of hash you generate from Node js ,Let me see if i can help ?
    – Rangesh
    Sep 13, 2017 at 10:36
  • Sorry I wasn't clear. I'm generating a hash with web3.sha3 but on nodejs. I then want to send that hash to the contract on the blockchain.
    – mcansado
    Sep 13, 2017 at 10:37
  • I guess then it must fit into bytes32 , As per the documentation it returns an hash of 32 bytes. github.com/ethereum/wiki/wiki/JavaScript-API and also make sure its not hex encoded.
    – Rangesh
    Sep 13, 2017 at 10:45

1 Answer 1


The Sha3 hash generated by web3 or solidity fits into bytes32 and don't require any special datatype to hold the has generated.

Reference : https://github.com/ethereum/wiki/wiki/JavaScript-API

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.