0

Following this topic, in the last reply there is a way to calculate the tokens transferred within the transaction but the last step is incomprehensible. How did he calculate the value of the tokens and what is the math behind it?

0x54ca7578dcf8bb7aa0 = 1.5641152016500001e+21

Laralex
  • 26
  • 2
  • In the second answer https://ethereum.stackexchange.com/a/72831 the values were obtained from the "input" field. – Ismael Dec 08 '21 at 20:08
  • @Ismael Yes, I meant exactly that answer, not the last one, my mistake. – Laralex Dec 09 '21 at 08:26
  • 1
    The answer is pretty clear to me considering the input field the first 4 bytes (0xa9059cbb) are the transfer method id, then 32 bytes are the address, then 32 bytes are the value transferred. The value is in the base units so you have to divide by 10^decimals to get the amount of tokens. – Ismael Dec 09 '21 at 14:30
  • So what is the exponent number that you mean by "decimal"? – Laralex Dec 09 '21 at 16:01
  • 1
    decimals is a function in the ERC20 abi that returns the numbers of decimals used by the token. Most tokens have set it to 18, but there are some that have less that 6. – Ismael Dec 09 '21 at 17:49
  • Thanks, dude! Absolutely what I needed. – Laralex Dec 10 '21 at 12:30

0 Answers0