How Ethereum Manages Accounts

Recap

In our previous series, we covered the following articles:

In this article, we learn how accounts are created and managed in Ethereum.

 

Ethereum Account

As we discussed earlier, instead of the UTXO model, Ethereum manages accounts and transactions differently than Bitcoin. In Ethereum, it introduces the world state concept, the collection of all accounts on the blockchain network. World state presents the global state of the Ethereum network, which is constantly updated following any transaction execution. It is a kind of a global database, which is replicated to all Ethereum nodes behind the scene.

Like your bank account, an Ethereum account is used for holding ethers and transacting with each other. It has a 20-byte cryptographic address, an account balance, and state transitions between accounts. The address identifies the owner of the account.
In addition to the address, an Ethereum account contains four fields:

  • Nonce: A counter used to identify distinct transactions
  • Balance: The account’s current ether balance
  • Contract code: Optional cryptographic hash code pointing to smart code associated with the contract creation
  • Storage: Optional cryptographic hash code pointing to the account’s storage

The following diagram further illustrates the structure of an Ethereum account:

Ethereum blockchain

In Ethereum, a transaction is a state transition of account from one state to another, which is initiated by an external entity. All transactions, whether it is ether movement from one account to another or smart contract code execution, will be collated into a block. Also, the resulting account states and transaction receipts are added to the block too. The new block will be mined by the blockchain network and added to the blockchain. Data in the blockchain is stored in supporting storage, usually a database. Depending on the Ethereum client implementation, it may be stored into a different type of database. For example, the Geth implementation uses Google LevelDB as the underlying database implementation for the global state, as shown here:

Ethereum blockchain

 

We will get into different types of accounts in the next section.

Two types of accounts

Accounts play an essential role in Ethereum. Ethereum introduces two types of accounts:

  • One is the Externally Owned Account (EOA), which is used for ether transfer and is controlled by private keys. There is no code associated with EOA.
  • Another one is a Contract Account (CA), which is used for contract creation and smart code execution. The EVM activates and executes the smart contract code logic whenever the contract account receives a message. Beyond normal operations, it may read from and write to internal storage or invoke smart contracts on the other contracts.

They are both state objects; an EOA has a balance, and a CA has both a balance and storage. Without CAs, Ethereum would be limited to the mere transfer of value between accounts, as with Bitcoin.

 

Externally owned account

Just like your personal or business account in a financial institute, an EOA is associated with an external entity as an owner who has an interest in the account or has ownership of the underlying cryptoassets. Every EOA has a pair of cryptographic keys. It is controlled by the owner’s private key. The owner uses its private key to digitally sign all transactions so that the EVM can securely validate the identity of the senders. In the world state, the account is linked to a public address, which is generated based on the owner’s public key. We will talk about the address in detail in the Address and wallet article, as part of the discussion about the Ethereum wallet.

The following diagram shows the structure of the EOA:

Ethereum blockchain

As shown here, EOA has a balance associated the address, mainly used for ether transfer.

 

One-to-One Live Blockchain Classes

Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.

 

Contract account

A CA, or a contract, has an ether balance and associated code, which is linked to the smart contract code in an EVM. It may have optional storage, which is pointing to EVM storage. A state change in a contract account may involve an update of the ether balance, the associated data in the storage, or both. A contract account has an associated address too, which is calculated using the Keccak-256 hash function, based on the address of its creator (sender) and the nonce:

Ethereum blockchain

The associated smart contract code is executed when it is triggered by transactions or messages received from other contracts. Once a new block is added to the blockchain, all participating nodes will execute the contract code again as part of the block verification process.

 

Next Article

In our next article (How Ethereum Manages Transactions), we discuss how transactions are processed and managed in Ethereum.

This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.

Resources

coming soon