2

I read that smart contracts don’t have a private key, so they can’t sign a transaction. My question is: when a smart contract starts a transaction to an EOA, how are we sure that the smart contract made the transaction if it doesn’t sign anything? I’m new in this world and I'm still studying English, so please forgive the mistakes. Thanks you

1

Only an EOA can sign and send a transaction. It can be addressed to a contract in which case the contracts functions must run.

A contract's functions can send messages and/or value to other contracts in which case they also run, or to an EOA which just receives because it has no code.

All of this happens approximately instantaneously (after mining) because it is all considered part of a single atomic transaction that must either complete entirely or fail.

Hope it helps.

  • So, when i send a transaction to a smart contract, the miner execute the code and, if the smart contract want to send message, the miner add the message transaction? – GBis Aug 31 at 23:50
  • The miner includes the transaction (inputs) in a block. Every full node runs the transaction to evaluate what it does for themselves. Running the transaction includes interactions with other contracts or EOAs. – Rob Hitchens - B9lab Sep 1 at 0:37
2

It's not so much about whether a smart contract has a private key or not; it's more about the fact that smart contracts can't initiate a transaction. All transactions are started by an EOA to either a smart contract or to another EOA.

If a transaction is sent to a contract the contract may include functionality to call another address within the same transaction (be it to another contract or to an EOA). We can always check msg.sender to see where the transaction came from (who was the previous relayer - the very very original sender is visible with tx.origin).

1

The smart contract can only send a transaction to an EOA if the transaction was initiated by an EOA. Smart contracts cannot initiate a transaction because they do not have a private key and cannot sign a transaction, as you said.

When value is being sent from a smart contract to an EOA, what is really happening is an EOA sending a transaction to the network that tells the smart contract to send value to the other EOA.

  • 1
    Thank you for the corrections and for the answer, I have a further doubt, you say: “an EOA sending a transaction to the network that tells the smart contract to send value to the other EOA“, so when the smart contract send value it mades a transaction, right? If true, how miners verify that the transaction is made by the smart contract? – GBis Aug 31 at 16:22
  • Yes, every value transfer on Ethereum is through a transaction. For example, here is a transaction from an EOA (0x134...) to a contract (0x0d8...) that initiated a transfer of 31.71388712 BAT from the original EOA (0x134...) to a new EOA (0xdda...). Note: the second EOA (0xdda) could have also been a contract as well—it does not matter where the value gets sent to. – shane Aug 31 at 16:27
  • 1
    So, like in your example, the smart contract “modifies” the original transaction? – GBis Aug 31 at 16:35
  • No it does not. The sending EOA creates a transaction and signs it with his private key. This transaction tells the contract how to behave and what to do (it does this in the data field of the transaction). The transaction is never "modified". When the transaction is sent to the network, Ethereum processes what the transaction instructed it to do, which, in this case, was to send tokens to another address. – shane Aug 31 at 16:39
  • 1
    Ok, therefore an eoa sends a transaction to a smart contract and when the miner verifies that transaction runs the code of the contract and in case add the new transaction “made” by the contract? Thank you for your patience and can you tell me where study the implementation of the “protocol” – GBis Aug 31 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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