Search code examples
ethereumweb3js

Get token transfer detail from transaction hash with web3js


enter image description here

With web3js, how do you figure out that there was 40000 tokens transfer from the transaction's hash?


Solution

  • There's a very good blog post on Medium using the exact method you're interested in.

    (Stealing from the post):

    1. Retrieve the input data from web3.eth.getTransaction() This will return the hex data for the function and parameters sent in the transaction. It will look something like 0xa9059cbb0000000000000000000000007adee867ea91533879d083dd47ea81f0eee3a37e000000000000000000000000000000000000000000000000d02ab486cedbffff.
    2. The first 32 bits (0xa9059cbb) is the sha3 encoded text of the function signature.
    3. Every 256 bit block after that is an argument passed in.
    4. After parsing out the block corresponding to the number of tokens in the parameter list, use web3.utils to convert to decimal.