How to pass Values in Transfer Event

I am emitting 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 of the emit 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

1 Like

I think you can get what you want.

When you send a transaction, you can use the event emitter, such as

web3.eth.sendTransaction({from: 'account1', to: 'account2', data: ACTUAL_CODE}).on('receipt', function (receipt) { })

you can just print the receipt to see what is it.

And for the value from and to, they are modified by indexed, so maybe you should try to find them in the array named topics.

1 Like

Thank you @Skyge 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);

As previously.

Regards, J

2 Likes