0

When transactions are made the sender is identified by his signature. But Contracts dont have a private key to sign any transaction or message. So I have some questions:

Can a Contract initiate a transaction? I mean transfering ETH from his account to another EOA or Contract. And if yes, will this transaction be included in the transaction list? And how do they sign the transacion?

2 Answers 2

3

No, contracts can't initiate transactions.

But yes, they can transfer ETH and make calls to other contracts, etc., but only as part of a transaction initiated by an externally owned account (EOA).

Etherscan calls those "internal transactions," but they're not technically transactions at all.

2
  • Then if Contract A transfers ETH to my account, I wont know where it came from until I look into the transaction that triggered the contract and see the code?
    – hadamard
    Commented Mar 11, 2019 at 22:55
  • Well, Etherscan will just list it (as an "internal transaction"). I think many tools will do the same.
    – user19510
    Commented Mar 11, 2019 at 23:58
0

Contracts do not transact. Externally owned accounts (users) make transactions.

A user can make a transaction as a sender, to a contract (recipient). In this case, a user wants a contract's specific function to be run and change the world state. The transaction is signed by the user's private key. So the miner hears about the transaction and facilitates the user's request. The miner runs the code to get the next state of the Ethereum blockchain.

After the miner publishes a block that includes the above transaction, every full node in the ecosystem hears about the new block and runs the code for themselves (for every transaction in the new block) to get to the new state and reach consensus (agree with the rest of the world on the state)

The code that the user asks to be run could send funds to the contract or withdraw funds from the contract or whatever logic can be implemented with Solidity.

The implementation of the function should check whether the user is allowed to run the code. In any case of error, e.g. out-of-gas error, data type overflow error, divide by zero error, array-out-of-index error, etc. the miner will include the transaction in the block and the rest of the nodes will verify that the transaction happened and failed, so no change of world state has occurred.

2
  • Regarding the last paragraph, miners will and usually do include your transactions which fail for whatever reason (out of gas, divide by 0, etc.). Blocks containing those transactions also are still valid and nodes will sync to them
    – natewelch_
    Commented Feb 9, 2023 at 20:05
  • ok. My bad. Thanks for the addition, @natewelch_! I will edit my answer. Commented Feb 12, 2023 at 16:22

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.