0

What's the best way to achieve the equivalent hashing in Java as below in Solidity? keccak256(abi.encodePacked(arg1,arg2,...))

2

One simple way is to use StringBuilder to append the strings as arguments for kaccak256, then to use library web3j to use sha3 method.

    StringBuilder sb = new StringBuilder(arg1);
    sb.append(arg2);
    sb.append(arg3);
    byte[] hash = Hash.sha3(Numeric.hexStringToByteArray(String.valueOf(sb)));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.