I want to hash two values(integer and string) in contract and get the same hash using these values at backend, but can't quite figure out what to do. Here are contract and JS code below.

pragma solidity ^0.4.0;
contract Contract {
    function hashIt(string a, uint b) returns(bytes32){
        return sha3(a, b);

Input: "1", 1

Output: 0x79e6f3a7968620dde8ba64f1f6d03f034d481c27d094c568f6475e60a9dbc4dc


Input: ["1", 1],

Output: 0x4535a04e923af75e64a9f6cdfb922004b40beec0649d36cf6ea095b7c4975cae


Input: "1", 1

Output: 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6

  • Just a quick idea, converting both into strings and concatenating might help., at least for unifying the input.
    – jeff
    Mar 2, 2017 at 12:59
  • @jeff, In the actual contract I hash timestamps that are generated inside the contract by solidity 'now()' function. It's possible to cast it to string inside the contract, but I believe it involves the use of libraries and should generally be used as a last resort.
    – manidos
    Mar 2, 2017 at 13:17
  • Yes, I thought you were computing these values with web3. But inside the contract, string manipulation is hard, even impossible in some cases.
    – jeff
    Mar 2, 2017 at 21:10

1 Answer 1


This is not an answer but I dont have enough reputation to comment. Have you looked at How does Solidity's sha3 / keccak256 hash uints? ?


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.