I am emitting within a function the following in a solidity smart contract.

emit Transfer(address(0), to, tokenId)

In my front-end JavaScript code, I am reading the values as follows:

let transfer = receipt.events.Transfer.returnValues.tokenId

If I declare my event using only the tokenId parameter (as below) in my smart contract, I am receiving the values of all three parameters in my front-end and everything works properly.

event Transfer(uint256 tokenId);

However, if I declare the event as follows with the three parameters, following the standard practice, I am no longer receiving any values and it no longer works!

event Transfer(address indexed from, address indexed to, uint256 tokenId);

What am I missing?

Thank you. J

  • Can you see if the event is getting emitted? – hrkrshnn Feb 16 at 13:13
  • The compilation should generate a new ABI with proper definitions. Perhaps the frontend is using and old ABI without the new event, or it is using the address of the previous contract without the new event. – Ismael Feb 16 at 18:39
  • @Ismael, yes, I am using the proper ABI. – JF0001 Feb 17 at 1:17
  • Thank you @hrkrshnn. When I use only the tokenId param within my declaration of the event, I am actually receiving all three values emitted by the event (i.e. returnValues with the "from", "to" and "tokenId" fields.) When I use the 3 parameters for the event declaration, I obtain the following error: TypeError: Cannot read property 'returnValues' of undefined – JF0001 Feb 17 at 1:36
  • I was able to make it work properly using the following: event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); Instead of: event Transfer(address indexed from, address indexed to, uint256 tokenId); – JF0001 Feb 17 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.