# Account State

Accounts play a crucial role in Ethereum's blockchain, facilitating transactions and maintaining the network's overall functionality. In Ethereum, each account has a state consisting of several key components that provide essential information. This text explores the significance of these components and their role in Ethereum's account state, shedding light on the distinctions between **Externally Owned Accounts (EOAs)** and **Contract Accounts**.

## Understanding Externally Owned Accounts and Contract Accounts

\
**Externally Owned Accounts (EOAs)** and **Contract Accounts** play crucial roles in managing and interacting with the blockchain network. This text explores the key characteristics and distinctions between these two types of Ethereum accounts, shedding light on their control mechanisms, transaction capabilities, account creation processes, and security considerations.\
\
**EOA** stands for **Externally Owned Account**. It refers to a type of Ethereum account that is controlled by an individual or an entity through a _private-public_ key pair. EOAs are commonly used by individuals and organizations to hold and manage ether (ETH), the native cryptocurrency of the Ethereum network, as well as interact with smart contracts.

Here are some key characteristics of **EOAs**:

1. **Control**: Controlled by private keys, which are used to sign transactions and provide proof of ownership. The private key allows the account owner to access and manage the account.
2. **Transaction Initiation**: Initiate transactions on the Ethereum network, including sending ether to other accounts or interacting with smart contracts by executing functions defined within the contract.
3. **Account Creation**: Creating an **EOA** does not incur any cost. It can be done by generating a new key pair, and the account address is derived from the public key.
4. **Transaction Security**: **EOAs** use a nonce, a sequence number that ensures the uniqueness of each transaction sent from the account. This helps protect against replay attacks, where signed transactions are maliciously repeated.
5. **Key Pair**: Consists of a cryptographic pair of keys – a public key and a private key. The public key is used to derive the account address, while the private key is kept secret and used to sign transactions.

**Contract account** refers to a different type of Ethereum account known as a smart contract account. It is a type of account that is deployed as a smart contract on the Ethereum network and is controlled by the code within the smart contract.

Here are some key characteristics of contract accounts:

1. **Control**: **Contract accounts** are controlled by the code deployed within the smart contract. The behavior and functionality of the account are determined by the code written in a programming language such as Solidity.
2. T**ransaction Execution**: Can execute transactions in response to receiving a transaction from an **external account**. The code within the smart contract defines the actions that can be performed, such as transferring tokens, updating storage, or creating new contracts.
3. **Account Creation**: Creating a **contract account** incurs a cost because it involves deploying a smart contract to the Ethereum network. The cost is associated with network storage and computational resources required for the deployment.
4. **Private Key**: Unlike **EOAs**, contract accounts do not have private keys associated with them. They are controlled entirely by the logic and rules defined within the smart contract code.

|                | External Owned Accounts (EOA) | Contract Account |
| -------------- | ----------------------------- | ---------------- |
| Controlled By  | People                        | No One           |
| Trigget TXs    | Yes                           | No               |
| Code & Storage | No                            | Yes              |

## Understanding the Account State in Ethereum: Exploring the Components

<figure><img src="https://3547655941-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRVaGqrTkWVRFb9yH5Pt5%2Fuploads%2FHibKNxaDkMHZCCvuwlF6%2Fimage.png?alt=media&#x26;token=077041bb-d997-4f4e-aecb-9b41037e5449" alt="" width="229"><figcaption></figcaption></figure>

\
In Ethereum, accounts play a crucial role in the execution of transactions and the overall functioning of the blockchain. Each account in Ethereum has a state associated with it, which is composed of four main components: **nonce**, **balance**, **code hash**, and **storage root hash**.&#x20;

These components serve different purposes and provide essential information about the account.

1. **Nonce**: The _**nonce**_ is a field in the Ethereum **account state** that represents a counter. For **externally-owned accounts** (EOAs), the **nonce** indicates the number of transactions sent from that account. For **contract accounts**, the _**nonce**_ represents the number of contracts created by that account. Each transaction or contract creation from an account must have a unique _**nonce**_ value, ensuring the order and integrity of operations. The _**nonce**_ also acts as a safeguard against replay attacks, where signed transactions are repeatedly broadcast and re-executed.
2. **Balance**: The _**balance**_ field in the **account state** denotes the amount of cryptocurrency owned by the account. In Ethereum, the base unit of currency is called _**wei**_, and there are 10^18 wei in one ether (ETH). The _**balance**_ field reflects the number of wei held by the account and is used for value transfers, including transaction fees. It represents the account's financial resources within the Ethereum network.
3. **Code Hash**: The _**code hash**_ is a unique identifier that represents the code associated with an Ethereum account. **EOAs** are controlled by private keys and do not have any code associated with them. On the other hand, **contract accounts** have code that can execute operations when triggered. The _**code hash**_ ensures the integrity and immutability of the account's code. For contract accounts, the _**code hash**_ field stores the hash of the account's code, while for **EOAs**, it is the hash of an empty string.
4. **Storage Root Hash**: It is a reference to the root node of a **Merkle Patricia Tree** that encodes the storage contents of an Ethereum account. Ethereum uses a **Merkle Patricia Tree** data structure to organize and store the storage of each account. The storage consists of a mapping between 256-bit integer values and their corresponding values. The storage root hash allows for efficient retrieval and verification of the account's storage data. It serves as a pointer to the storage contents and helps maintain the integrity of the storage.\
   \
   A **Merkle Patricia Tree** is a data structure used to organize and store the storage contents of each account. It is a specific type of trie (a tree-like data structure) that utilizes cryptographic hashing to efficiently store and retrieve data. In the context of Ethereum, the **Merkle Patricia Tree** is particularly useful for representing the key-value pairs that make up the storage of an account. It allows for fast and secure access to specific storage values by using a hash-based indexing system. In the next module, we will delve deeper into the inner workings of the **Merkle Patricia Tree** and explore its role in maintaining the integrity and efficiency of Ethereum's storage system.



&#x20;
