How to get contract internal transactions

  • I'd like to get the contract internal transactions like: https://etherscan.io/address/0xd654bdd32fc99471455e86c2e7f7d7b6437e9179#internaltx

    I'm using web3 API. Is there any way to do it? Where do they appear in the blockchain?

    hopefully the answer will explain what an internal transaction is

    They are the transactions triggered by the contracts.

    sure, but still not sure what it means. I don't recall a solidity keyword for this. link?

    @PaulS It's any transaction sent via the `address.send()` or `address.call()` functions in Solidity

    No, there are other ways to 'send' ether like suicide() or when you create a new contract

  • There's not currently any way to do this using the web3 API. Internal transactions, despite the name (which isn't part of the yellowpaper; it's a convention people have settled on) aren't actual transactions, and aren't included directly in the blockchain; they're value transfers that were initiated by executing a contract.

    As such, they're not stored explicitly anywhere: they're the effects of running the transaction in question on the blockchain state. Blockchain explorers like etherscan obtain them by running a modified node with an instrumented EVM, which record all the value transfers that took place as part of transaction execution, storing them separately.

    Got it! Do you know if there is a plan to add a sort of mechanism to get these transactions or I must create an instrumented EVM.

    I'm not aware of ongoing work to add an API like this, though there could be; if your goal is to get internal transfers for a given transaction, that'd be practical. If your goal is to get all transfers into an account, though, this isn't sufficient - and there's a bug for that.

    I already have the tx list for non contract transactions but I'd like to add the 'internal transactions' to the transaction list. Do you think that an instrumented EVM could work for that?

    @PabloYabo It would, but if what you care about is "all transactions _to_ this account", you have to run every single transaction through it, in case it produced a transfer to the account you care about. If you care about "all value transfers initiated by this transaction", then you can run it just on that transaction.

    The idea is to have a db with all transactions of all accounts, so executing all the transactions is a possible in this scheme. We are now getting all blocks, transactions and receipts.

    @PabloYabo In that case, such a hypothetical API would probably serve your purposes - but in the meantime, you'll have to instrument the EVM yourself.

    @PabloYabo please explain how did you manage to _have the tx list for non contract transactions_?

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM