25

I need to get all contract internal transactions. To do it, I'll need to instrument Ethereum EVM.

My question is: what I should do to get the transaction details? Right now, I'm looking to the code but if someone can point me to the correct part of the code it will be appreciated.

4
  • Question improvement suggestions: (1) specify what you mean by "contract internal transactions". (2) add a link to the code (part of the code) that you are looking at.
    – zanzu
    Commented May 30, 2016 at 18:29
  • I'm looking to go-ethereum project in GitHub: github.com/ethereum/go-ethereum
    – Pablo Yabo
    Commented May 30, 2016 at 18:50
  • A starting point appears to be github.com/ethereum/go-ethereum/blob/master/core/vm/…
    – eth
    Commented May 30, 2016 at 19:19
  • Yes, I was there. I'm looking for someone who did it to simplify the task.
    – Pablo Yabo
    Commented May 30, 2016 at 19:20

1 Answer 1

32

To do this, you need to define a VM log collector, which implements StructLogCollector. This function gets called on every step of the VM, and is provided with copies of the memory, stack, and modified parts of the storage, along with the program counter, current opcode, gas left, and other data. It's also called when an error occurs that causes a transaction to fail.

To extract the data you want, you need to watch for several things: 'CREATE', 'CALL', 'CALLCODE' and 'DELEGATECALL' opcodes, which invoke new contracts or accounts and potentially transfer value, and 'SUICIDE' which returns value to the caller. You also need to watch for anything that causes a call to return, and for the aforementioned errors.

While tracing, you need to maintain a stack that represents the stack of calls made by the current transaction, with each stack frame containing a list of value transfers that have been made so far. A non-error return pops a stack frame, adding all its value transfers to the frame below. An error return pops the frame, discarding all the transfers. When you pop the final frame, the set of transfers on it are the ones that were finalized as part of the transaction.

An implementation of all of this can be seen as part of my Etherquery code.

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.