1

In Solidity, I am encoding a string and some empty bytes like so:

bytes memory _queryData = abi.encode("TwitterContestV1", abi.encode(bytes("")));
bytes32 _queryId = keccak256(_queryData);

I haven't found a solution that produces the same queryId in JavaScript. I've tried solutions using ethers.js & web3.js. For example, this:

const {ethers} = require("hardhat");
const {keccak256} = require("@ethersproject/keccak256");
...
const abiCoder = new ethers.utils.AbiCoder;
const queryData = abiCoder.encode(["string", "bytes"], ["TwitterContestV1", "0x"]);
const queryId = keccak256(queryData);
console.log(queryId)

Produces: 0xfa582019f544379a24648958ea92b04b85fb4dc8c8d379de150096012d02d8da But the Solidity queryId (hashed queryData) is: 0x7848658e5249a88a2cd61c63cb7114555cc79c9a491a7d2edf3b203236917a21

1

1 Answer 1

1

oh, this is how:

const queryData = abiCoder.encode(["string", "bytes"], ["TwitterContestV1", abiCoder.encode(["bytes"], ["0x"])]);

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.