2

I am using Etherscan API to get transaction and other details for addresses.

I need to find out no. of tokens transferred between two addresses. For Ex - for Below TxHash I see 1564+ tokens transferred. When I use this API call I see from and to address but not token value. enter image description here

Edmund Edgar
  • 16,897
  • 1
  • 29
  • 58
garg10may
  • 724
  • 3
  • 9
  • 18

3 Answers3

4

Here's json result from your api call:

{
    jsonrpc: "2.0",
    id: 1,
    result: {
        blockHash: "0x8fe66b0c15a1c1155338bb5628db55f05cfe72d1194931134b4721cd07e9eda7",
        blockNumber: "0x416850",
        from: "0x167a9333bf582556f35bd4d16a7e80e191aa6476",
        gas: "0x13880",
        gasPrice: "0x4e3b29200",
        hash: "0x03430ecdf52d37a8d3645fa9b19c072ec367edbd0d4eba3cc1c7f7c5e7dcc7d2",
        input: "0xa9059cbb0000000000000000000000007a2641bb2fb31ccd33ba5488c886c3bc4714ec6b000000000000000000000000000000000000000000000054ca7578dcf8bb7aa0",
        nonce: "0x15a82",
        to: "0x9a642d6b3368ddc662ca244badf32cda716005bc",
        transactionIndex: "0x2a",
        value: "0x0",
        v: "0x25",
        r: "0x790a06d5773006ecbc719354d966d100470e6267a68d3446ca0ebfd8df4452b5",
        s: "0x4e58eb2997a3c8add1386a47a71ac5bb915a2a53343883ea1ea4d8e69a6be486"
    }
}

Please take care of the input field:

  • First 4 bytes is method hash:

    a9059cbb
    
  • Next 32 bytes is target address:

    0000000000000000000000007a2641bb2fb31ccd33ba5488c886c3bc4714ec6b
    
  • Last 32 bytes is value of ERC20 tokens transferred:

    000000000000000000000000000000000000000000000054ca7578dcf8bb7aa0
    

0x54ca7578dcf8bb7aa0 = 1.5641152016500001e+21

jun.wu
  • 41
  • 1
2

Given a txtid is possible to retrieve the logs of the transaction via web3 using the getTransactionReceipt() function.

Alternatively, you can use this API exposed by etherscan.io: https://etherscan.io/apis#logs

Remember to set the right topic, as mention in this other answer: What is topics[0] in Event logs?

phra
  • 83
  • 8
  • Yes eventually I am trying this, but this would require traversing all transactions of a address and check for that address in all logs. – garg10may Sep 18 '17 at 12:45
  • 2
    Also I am not sure how to find topics, without topics I can't traverse all the logs since they would need pagination which is very ineffective since there are 400k blocks. Still exploring. Was hoping there was some direct way. – garg10may Sep 18 '17 at 12:47
0

@jun.wu,

x54ca7578dcf8bb7aa0 = 1.5641152016500001e+21

How did you come to this conclusion? Is there any formula or what?

Laralex
  • 26
  • 2