Get token transfer detail from transaction hash wi

2019-03-31 09:36发布

enter image description here

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

3条回答
冷血范
2楼-- · 2019-03-31 10:02

Ethereum smart contract transaction input data decoder Uses ethereumjs-abi for decoding. https://github.com/miguelmota/ethereum-input-data-decoder

查看更多
Bombasti
3楼-- · 2019-03-31 10:05

I will try to show an example how you do this:

lets take this Tx:

0xa543a3a7b6498bc9aec6989d99228be07855cdd23cfbf491489e8d4088b4a94c

This is Tx to a contract that send some amount of token to address The received data from web3.eth.getTransaction() input:

0xa9059cbb00000000000000000000000092e707288dc221d864cf4a8c710c143e97225d7d000000000000000000000000000000000000000000000059f37b9220158a8000

Now the first 34 bits represent text of the function signature (0xa9059cbb)

The next 256 bit block represent the address we want send the token to:

00000000000000000000000092e707288dc221d864cf4a8c710c143e97225d7d

The second block represent the amount (in hex) of tokens that were sent to the address:

000000000000000000000000000000000000000000000059f37b9220158a8000

We will convert the hex to decimal with any conversion function or with this web site: https://www.rapidtables.com/convert/number/hex-to-decimal.html

we will see that after the conversion we get 1659305000000000000000 it the number of token that sent to the address.

I hope it help

enter image description here

查看更多
【Aperson】
4楼-- · 2019-03-31 10:19

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.
查看更多
登录 后发表回答