0

After submitting a transaction. I'd like to get information from the event generated.

event GameCreated(uint256 gameId, uint256 wager, address Player1);

We tried this with both Ethers Library and Web3.
ethers.utils.defaultAbiCoder.decode()
https://docs.ethers.io/v5/api/utils/abi/coder/#AbiCoder
web3.eth.abi.decodeLog()
https://web3js.readthedocs.io/en/v1.2.11/web3-eth-abi.html#decodelog

    const object = ethers.utils.defaultAbiCoder.decode(['uint', 'uint', 'address'], 
    "0x000000000000000000000000000000000000000000000000000136b8380cec84000000000000000000000000000000000000000000000000432b4ada5355162f00000000000000000000000000000000000000000000000024cb65b70804a8c9000000000000000000000000000000000000000000000000432a14221b4829ab00000000000000000000000000000000000000000000000024cc9c6f4011954d",
    )
    console.log(object[0].toNumber())
    console.log(object[1].toString())
    console.log(object[2])

Here is a screenshot of the event log from Mumbai Polygon Scan.

enter image description here

Expected values are:

  • gameId: 1
  • wager: 1
  • Player1: 0xD544F62f52497d84884f17CC923a8BA966A75537

Actual Values returned by both Ethers and Web3 libraries:

  • gameId: "514942734672828"
  • wager: "4836593396267459283"
  • Player1: "0x0000000000000000000025D21dE5f3de05B8346f"

There has to be some sort of conversion that I'm missing.
Any guidance would be greatly appreciated.

2
  • The object you're trying to decode 0x00..4d is way different than the one from polygonScan. In particular it has 5 arguments instead of 3. I think you're decoding the wrong thing. To get the logs you have to pick the transaction receipt and look at the logs key. Then you have to pick the right log by checking the topics[0] value.
    – 0xSanson
    Commented Oct 2, 2022 at 11:14
  • You're absolutely right. There was an array of 2 logs. And my brilliant brain chose the wrong one -_____- Thank you so much. Commented Oct 2, 2022 at 14:58

1 Answer 1

1
data="0x000000000000000000000000000000000000000000000000000136b8380cec84000000000000000000000000000000000000000000000000432b4ada5355162f00000000000000000000000000000000000000000000000024cb65b70804a8c9000000000000000000000000000000000000000000000000432a14221b4829ab00000000000000000000000000000000000000000000000024cc9c6f4011954d"

decode data should be 5 parameters.

0x000000000000000000000000000000000000000000000000000136b8380cec84 0x000000000000000000000000000000000000000000000000432b4ada5355162f 0x00000000000000000000000000000000000000000000000024cb65b70804a8c9 0x000000000000000000000000000000000000000000000000432a14221b4829ab 0x00000000000000000000000000000000000000000000000024cc9c6f4011954d

So,the data you have given is wrong.

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.