I', getting to know the Ethereum technology (so rookie level). By far, with the free APIs (etherscan.io, ethplorer.io, coingecko) I have been able to build a "watch wallet". It looks like this:
But I can't seem to find the API which gives me more detail about all the Transactions in the given wallet. API does give me the hash, block, gas, status, address (from/to), etc… But I don't know the tokens (assets) that were involved in those transactions and I don't know which action took place (Sent/ Received/Swapped/Approved …)
Here's the raw info I get from the api (image 2), can someone guide me to the next step of how to extract those detail data?
P/s: What I'm trying to achieve looks like this (Image 3: Zerion app)
Best Answer
First, you are not querying the right endpoint. If you want to fetch ERC-20 events, you must do the following query :
Notice that unfortunately, the
input
field value isdeprecated
. This is what you should have used to determine the event (Trade
,Approval
,Send
...)Fortunately, we can call another method to get this data. Let's get the input data for the last transaction, so transaction with hash
0xdceb6a76cc83802ddabf8efc0b0458dfa9150866df3ad826686e47b303259cd8
You can then get the encoded input data :
0xa9059cbb000000000000000000000000ddbd2b932c763ba5b1b7ae3b362eac3e8d40121a00000000000000000000000000000000000000000000000000005af3107a4000
To decode it, you can use abi-decoder. You must provide to abi-decoder the abi of ERC-20 contract :
Then do something like this :
Note : instead of getting your hands dirty with etherscan api, you should try using web3js instead