3

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

2
  • I am solving same problem, do you get the decision? Commented Jan 9, 2018 at 7:48
  • Hello All, Have you found any solution for the same ? Thanks
    – Mangesh
    Commented Sep 6, 2018 at 10:35

3 Answers 3

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

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?

2
  • 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
    Commented Sep 18, 2017 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
    Commented Sep 18, 2017 at 12:47
0

@jun.wu,

x54ca7578dcf8bb7aa0 = 1.5641152016500001e+21

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

2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Dec 9, 2021 at 11:01
  • This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
    – Julissa DC
    Commented Dec 9, 2021 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.