3

If I want to track ERC-20 token transfers in a transaction, even if they are the result of a smart contract execution I can just read the events.

However if a transaction has a call to a smart contract and that contract sends Eth somewhere, how do I detect that programmatically? I wish to know for an arbitrary transaction what addresses had their Eth incremented or decremented.

If this requires an archive node with debug module enabled, specifics on how to do this would be helpful.

Only other question on here that asks this is: How to scan ether transfer from smart contract to my addresses programmatically? but it didn't get an answer.

1 Answer 1

2

You are confusing two things:

  • Token transfers
  • ETH transfers

If you want token transfers just listen for Transfer events, very ERC20 - compliant token will emit this event no matter how deep in the stack frame it was issued:

Transfer(from, to, value)

doesn't require archival node, doesn't require a node at all if you use free API key from Infura

Now, if you want ETH transfer this is much more complicated.

You need trace every transaction in the block. The ETH transfers will be made by the following instructions:

CALL 
CALLCODE 
DELEGATECALL 
STATICALL 
CREATE
CREATE2
SUICIDE (SELFDESTRUCT)

there are also transfers made outside of the EVM , these are:

  • Buying gas for the transaction (before EVM is invoked)
  • Mining rewards (after block has been finished processing)

The trace log will contain stack, so to get the value of ETH transferred you need to read the last elements of the stack.

You do not need archival node if you want to generate data from present to future, but if you want past history archival node is a must. Also if you want to verify you have the correct implementation (without bugs) you will need archival node because Full node only keeps track of the last 128 blocks, state of older blocks is pruned

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.