Hello, I have a couple of questions regarding contract accounts in Ethereum.
I understand that smart contracts belong to the so-called contract account (as opposed to EOAs). Such accounts do not have private keys and can therefore “not initiate transactions, only react to these”. However, I have been told that smart contracts can interact with and call functions in other smart contracts.
Isn’t this an inherent contradiction? Or would you say that initiating a transaction is something different than calling a function or interacting with a smart contract?
Also regarding the missing private key in contract accounts, I thought Ethereum Addresses are generated using elliptic curves and a public-private key pair. How can a contract account (which has its own Ethereum address) not have a private key?
Good question!
Generally speaking, there are two types of the accounts:
Externally owned accounts(EOA)
Contract accounts
Yeah, there are some differences between them, for EOA, it is a combination of public address and private key, and for contract accounts, they do not have a corresponding private key. The contract is generated by user’s wallet when he deploys contract. Although it does not have a private key, it has internal code, and these code have got to be triggered by an EOA or another contract.
A.foo is implemented in such a way that calls to B.bar
With this setup, if You call A.foo then A will be callingB.bar in turn. All of this happens in the same transaction. Therefore, a transaction (a collection of function calls) can only be initiated by an EOA while function calls can be made from user to contract or contract to contract. You can distinguish between these two by using msg.sender (whoever called the function, it will be A from B's perspective) and tx.origin (the EOA that initiated it all). Notice then that a single transaction has a single tx.origin and potentally different msg.senders during its execution.