0

Etherscan contract details interface shows internal transaction which type of transactions comes under it.

enter image description here

0

2 Answers 2

1

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when a transaction with associated input data (contract interaction) is made to it. Source.


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. For more info, take a look at this, this and this.


To understand this, check out the following example:

The EOA address A wants to send some ERC-20 tokens to the EOA address C. To do this, the EOA address A should make a transfer transaction to the ERC-20 Contract address B, with these parameters:

tx_obj = {
            'from'      : EOA_address_A,
            'to'        : ERC_20_Contract_address_B,
            'value'     : 0,
            'data'      : data,
            'gas'       : estimated_gas,
            'gasPrice'  : web3.eth.gas_price,
            'nonce'     : web3.eth.get_transaction_count(EOA_address_A),
            'chainId'   : web3.eth.chain_id
            }

wherein

estimated_gas = self.w3.eth.estimate_gas({
            'from'      : EOA_address_A,
            'to'        : ERC_20_Contract_address_B,
            'value'     : 0,
            'data'      : data,
            'nonce'     : web3.eth.get_transaction_count(EOA_address_A),
            'chainId'   : web3.eth.chain_id
            })

and

data = contract_token.encodeABI(fn_name="transfer", args=[EOA_address_C, to_wei(amount, 'ether')])

wherein

contract_token = web3.eth.contract(address=ERC_20_Contract_address_B, abi=ERC_20_Contract_address_B_abi)

In this example, the EVM recognizes tx_obj as transaction parameters : 0 amount from EOA_address_A to ERC_20_Contract_address_B with "data" as data. This is called a transaction.

The so called Internal transaction is the consequence of this transaction. i.e., with this transaction made, by triggering the transfer function in the ERC_20_Contract_address_B and passing the "data" provided by this transaction, ERC_20_Contract_address_B's transfer function will be run and tokens will be transferred to EOA_address_C.

Because of this fact that running this function won't change the blockchain state (despite the main transaction), the EVM won't recognize this as a transaction and people conventionally call this an internall transaction. However, 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.

1
  • "Because of this fact that running this function won't change the blockchain state (despite the main transaction)". No, it does change the blockchain state, the storage of ERC_20_Contract_address_B is changed.
    – cifer
    Jul 10, 2022 at 15:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.