# About using ethers to sign EIP-191

**URL:** <https://forum.openzeppelin.com/t/about-using-ethers-to-sign-eip-191/21328>\
**Category:** General\
**Created:** [December 21, 2021, 4:05am UTC](https://forum.openzeppelin.com/t/about-using-ethers-to-sign-eip-191/21328 "2021-12-21T04:05:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Odette\_Taylor](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/odette_taylor/32/4350_2.png) [@Odette\_Taylor](https://forum.openzeppelin.com/u/Odette_Taylor)\
**Post date:** [December 21, 2021, 4:05am UTC](https://forum.openzeppelin.com/t/about-using-ethers-to-sign-eip-191/21328/1 "2021-12-21T04:05:21Z")

</div>

Related methods in this contract

```auto
        bytes32 criteriaMessageHash = getMessageHash(
            _type,
            paymentErc20,
            price
        );

        bytes32 ethSignedMessageHash = getEthSignedMessageHash(
            criteriaMessageHash
        );

        require(
            recoverSigner(ethSignedMessageHash, signature) == userAddress,
            "ThetanBoxPayment: invalid seller signature"
        );

    function getMessageHash(
        uint256 _boxType,
        address _paymentErc20,
        uint256 _price
     ) public pure returns (bytes32) {
        
        return keccak256(abi.encodePacked(_boxType, _paymentErc20, _price));
    }

    function getEthSignedMessageHash(bytes32 _messageHash)
        public
        pure
        returns (bytes32)
    {
        /*
        Signature is produced by signing a keccak256 hash with the following format:
        "\x19Ethereum Signed Message\n" + len(msg) + msg
        */
        return
            keccak256(
                abi.encodePacked(
                    "\x19Ethereum Signed Message:\n32",
                    _messageHash
                )
            );
    }

```

Try to use ethers API to encode

```auto
  const boxId = 1;
  const price = 10;
  const paymentErc20 = "0x0000000000000000000000000000000000000000";

  const getMessageHash = await BoxHubContract.getMessageHash(boxId,paymentErc20,price);
  console.log("getMessageHash ",getMessageHash);
  
   const getMessageHash2 = await ethers.utils.keccak256(hre.ethers.utils.defaultAbiCoder.encode(["uint256", "address" , "uint256"], [boxId, paymentErc20 , price]))
  console.log("getMessageHash 2 ",getMessageHash2);

```

Test getMessageHash after encoding! = getMessageHash2 , It seems that I use the normal API, help brother

```auto

```

---

<div class="post-metadata">

**Author:** ![gxmxni](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/gxmxni/32/15829_2.png) [@gxmxni](https://forum.openzeppelin.com/u/gxmxni)\
**Post date:** [July 26, 2022, 11:48am UTC](https://forum.openzeppelin.com/t/about-using-ethers-to-sign-eip-191/21328/2 "2022-07-26T11:48:36Z")

</div>

This is because the contract uses encodePacked, whereas in JS you're using the equivalent of encode. Since address is a 20-byte type, this will result in different hashes.

The correct ethers function to use here is solidityPack.
