0

I'm encoding a message using ethers' solidityPackedKeccak256()

const encodedMessage = ethers.solidityPackedKeccak256(
            ["address", "uint256", "uint256"],
            [deployer.address, TOKEN_ID, NONCE],
        );

I'm signing this message using -

  1. web3

     const { signature: signatureWeb3 } = web3.eth.accounts.sign(
                 encodedMessage,
                 HARDHAT_PRIVATE_KEY,
             );
    
  2. ethers

     const signatureEthers = await deployer.signMessage(encodedMessage);
    

Their outputs are -

web3 =  0xc5b8d6ae2203e7f90257162289e552fac04b5708d4fe6b4360e86c2855db059314357f66bf89a2f72858980aa390607598defcb5382fea437ac4da3f725a9b231b
ethers =  0xaf7cb82eee6050746f299888ccc2a888d6801bff3701975ed5a73c73238b12a624fa575c9f8222ecaed25d2071c108477c84ac79572ceedf226f7a010f24511d1c

The message for both functions is same. So Why are both signatures different? How do I get the same result from ethers as web3's?

1 Answer 1

1

You are using two different cryptography to sign the transactions on web3 and ethers.

Web3 soliditySha3() and for ethers solidityPackedKeccak256()

Instead you should implement web3.utils.keccak256() and ethers.utils.keccak256() to receive the same outputs signing ✍🏽 the message.

1
  • Actually i used the same encoded message for both signature functions. So the message being passed as parameter is same for both accounts.sign() & sign(). Still both are giving different outputs. I'll edit my question so it's more clear Commented Sep 21, 2023 at 14:37

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.