I have a parity node. I developed a web3.js interface on top of it.
I have APIs whose job is to fetch addresses' balances and transactions.
Example response of transaction API:
{ tx_hash: '0xc4a2db4211686f740885ad72ef5d424f5ba6d953d583ef39382e7c1c594ecab7',
nonce: 0,
block_hash: '0xf2b173625cf874387302295f408ef0876c04e5778e6ccacec63fe28ff268f9a3',
block_number: 5955478,
transaction_index: 184,
from: '0xAcc7662daDfCE9dA2C0d8ef7867C15A262c762D7',
to: '0x3495Ffcee09012AB7D827abF3E3b3ae428a38443',
value: '0',
time: '1531467099 Fri, 13 Jul 2018 07:31:39 GMT',
gas_price: '5000000000',
gas: 37351,
input: '0xa9059cbb000000000000000000000000c5c813994f9142d11d73b47e1437c81e27b4dae3000000000000000000000000000000000000000000000000b469471f80140000' }
value key is for ether/wei transfers only.
For ERC20 tokens:
- I fetch the
to
address and compare it to a list of supported erc20 contract addresses. - If there is a match, the transaction call was to erc20 contract and it wrote to the blockchain (
contract.send()
) - At this point I am lost. How to figure out which function of ERC20 standard contract was called?
- How to fetch how many tokens were transferred and to which address in this call?
Thanks for reading my query. Any help would be really great. You are free to use the linked git project.
UPDATE
If we use getPastEvents
function of web3.js and fetch all events, then a matching can be done against all transactions and I can figure out somehow how many tokens were delivered and when.
But this will be a complicated flow, and will be done per contract basis. Anything that can avoid calling events and figure out the details of the erc20 transactions? what if the contract didn't call any event?