State, Transactions, and Blocks
Since Ethereum is a blockchain, it contains blocks. Blocks contain the transactions, and due to their strict order, they represent the transaction history. Transactions in a block are ordered too.
The Block
An Ethereum block contains the following data: [Source: https://ethereum.org/en/developers/docs/blocks/]
Timestamp: The time when the block was mined in seconds from unix epoch.
Block number: The length of the blockchain in blocks when the block was created.
Difficulty: The hashing or staking effort required to mine the block given in a hexadecimal number.
Nonce: A value that needs to be found in combined with the mixHash, to prove that the block was mined through proof of work.
mixHash: A unique identifier for that block.
Parent hash: The hash of the block that came before the current block.
Transactions root: The hash of all transactions included in this block. A Merkle tree is used to calculate the hash.
State root: The hash of all account balances, contract storage, contract code, and account nonces. The hash is calculated using a Merkle/Patricia tree. The hash function is keccak256.
Receipt hash: The hash of the recipient information.
Transactions
Transactions contain several informations like:
Nonce: unique number of a transaction per account.
gasPrice: Amount of ETH paid for one unit of gas.
gasLimit: Max amount of gas a user is willing to spend in this transaction.
to: Recipient
value: Amount of ETH sent in this transaction to the recipient.
signature: v, r, s
init (optional): Used when a contract is created
data (optional): input data of the message call.
The State
In contrast to Bitcoin, Ethereum maintains a state. You can imagine the state as a large sheet of paper, where all balances, variables, and smart contracts are stored. A transaction changes the state.
We can express this as a formula:
Y(S, T)= S’
S is the old state
T is a transaction S’ is the new state
This is a major difference to bitcoin, where the “state” consists of unspent transaction outputs.
The state itself is a huge data structure that is called a modified Merkle-Patricia-Trie.
On the top of the Merkle-Patricia Trie, we have the root. And this root is part of the block that is confirmed by the miners.