4

I'm trying to code a signature like opensea does for approving the Terms of Service. To do so I'm using the ECDSA library.

This code in javascript using ethers:

const message = ethers.utils.solidityKeccak256(
  ['address'],
  [
    '0x00cF2CFA50bD1434C65F00Bf80867499492f5639',
  ],
)
console.log(message)

Gives me a different output as this code in Solidity:

address owner = 0x00cF2CFA50bD1434C65F00Bf80867499492f5639;
bytes32 public message = keccak256(
    abi.encodePacked(owner)
);

why is it so?

I checked this post and this one but they don't help me since they use WEB3 and I use ethers.

3
  • What hashes do you have in both cases?
    – FLCL
    Mar 14, 2023 at 16:49
  • ethers.js gives: 0x661483957cd349fdb3dba77e9ca622510d2429df42eba774af2c8ebf8fd6fad7 solidity gives: 0x5380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a
    – Loo
    Mar 14, 2023 at 17:21
  • your address has the wrong checksum, ethsum.netlify.app
    – Majd TL
    Mar 20, 2023 at 8:05

1 Answer 1

2
+50

Tried this:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract Test1 {
  address owner = 0x00cF2cfa50BD1434C65f00Bf80867499492F5639;
  bytes32 message = keccak256(
      abi.encodePacked(owner)
  );

  function test() public view returns (bytes32) {
    return message;
  }
}

and the result = 0x661483957cd349fdb3dba77e9ca622510d2429df42eba774af2c8ebf8fd6fad7 is the same as for ethers.

Btw solidity says owner's address is not good in terms of checksum. The example fixes that.

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.