tokens – How to Find the Incoming Balance of an ERC20 Token Using Its Transaction Hash

balanceserc-20tokensusdt

I know how to find the erc20 balance of an address. What I'm trying to find is the incoming token of a particular ERCs.
For example :

for a transaction, I managed to fetch its from_address, to_address (which will be the token address), also managed to decode its data field of method transfer(_to,_value), which is :

{
   "_to":"0xda79da67357FBA5C2B5D596D3e738C529D94F16E",
   "_value":196880000
}

_to is the destination address and _value is the desired amount. But what is the unit of that amount ??

In the above transaction it was 196.8 usdt transferred, but what is the standard to convert the value that is applicable to all erc20?

Best Answer

Within the context of smart contracts, token amounts are always denoted in integers. So, in your case, 196880000 tokens were transferred.

What makes this concept a bit tricky is the UIs which make the amount "more user friendly". In your case, the user friendly amount is 196.8.

I've earlier invented the terms absolute amount and display amount to separate these concepts. Contracts always operate on absolute amounts. To get a display amount from absolute amount, you check the amount of decimals the token has. In your case the token has 8 decimals, so you shift the decimal separator 8 spots to the left, resulting into 196.8.

Just to emphasize: the concept of decimals (and display amount) is only relevant for user interfaces. In reality always the absolute amounts are used.

Related Topic