Nethereum icon indicating copy to clipboard operation
Nethereum copied to clipboard

How to decode ERC20 event (Transfer or Approval) out from transaction log using Nethereum

Open Kane-Tang opened this issue 3 years ago • 4 comments

I tried to get ERC20 event like transfer or approval from transaction logs and it works when I tried on ERC721 while it fails for ERC20. Actually, for every transaction log I've already tested, the decoded object would all go null. Is there anything wrong with the Nethereum usage or due to some else reasons, the following is my demo code, could you please help with it? Thanks, @juanfranblanco

image image

Kane-Tang avatar Sep 20 '22 08:09 Kane-Tang

ERc20 event is not indexed the last parameter

juanfranblanco avatar Sep 20 '22 08:09 juanfranblanco

ERc20 event is not indexed the last parameter

you mean there are only two params for ERC20 event? According to https://ethereum.org/en/developers/docs/standards/tokens/erc-20/, it seems cover this, thanks, @juanfranblanco

Kane-Tang avatar Sep 20 '22 09:09 Kane-Tang

I tried to use txReceipt.DecodeAllEvents<TransferEventDTOBase>() instead while for most ERC721 events it works, for ERC20 it returns no events when it can be found on Etherscan according to the transaction hash. Is it the correct API to fetch ERC20 events or it only worked for ERC721, or my "TransferEventDTO" is incorrect? Could you please give me the sample to get ERC20 event from transaction receipt if my grammar is wrong. Great thanks, @juanfranblanco

Etherscan event link: https://rinkeby.etherscan.io/address/0xc7ad46e0b8a400bb3c915120d284aafba8fc4735#events, Transaction hash: 0x2b003012981d278bcaf086b2c0faf64a2e5b8cea2edca6eee6ee1a80277f71e8

Kane-Tang avatar Sep 22 '22 07:09 Kane-Tang

Could you please take a look at this question if convenient, thanks, @juanfranblanco

Kane-Tang avatar Sep 23 '22 03:09 Kane-Tang

@Kane-Tang

The 721 transfer has an extra index, see that "true" in the attribute of the property index

image https://github.com/Nethereum/Nethereum/blob/master/src/Nethereum.Contracts/Standards/ERC721/ContractDefinition/ERC721Definition.cs#L397

as opposed to erc20

image which value is not

https://github.com/Nethereum/Nethereum/blob/master/src/Nethereum.Contracts/Standards/ERC20/ContractDefinition/ERC20Definition.cs#L142

So they look the same but they are not, what you can do is to check the number of Topics for the matching log and switch accordingly.

juanfranblanco avatar Sep 26 '22 11:09 juanfranblanco