FullStack AI Hub
Studio
lesson depth
Mastery
not started · 0%

Ethereum Transactions: Signatures, Nonces, and State Roots

Follow typed transactions from signature and nonce checks through EVM execution, fee charging, trie updates, block inclusion, and consensus finality.

Freshness: current•10 min read•Distributed AI Platforms
Full Technical Reference Document

Mental model

Ethereum transaction processing turns a signed, typed envelope into an ordered state transition. The execution layer checks chain ID, nonce, signatures, fee bounds, and funds; runs the EVM against a prior state; then commits updated account and storage tries into a block state root. Consensus decides which block is canonical and finalized, so mempool acceptance alone is never a durable write.

Theory

Transaction envelope and account state

An externally owned Ethereum account has a nonce and balance. A contract account also has bytecode and a storage trie. The execution layer encodes an account as the nonce, balance, storage root, and code hash; account entries are placed in the state trie under the hash of the 20-byte address. A storage trie maps hashed slot keys to encoded values. The block header's stateRoot commits to the resulting world state, allowing a client with the relevant trie nodes to verify a path without trusting a database query.

A type-2 transaction carries a chain ID, sender nonce, fee caps, gas limit, destination, value, calldata, and access list. Its signature authenticates the serialized envelope. The chain ID prevents a signed transaction intended for one network from being accepted unchanged on another network with a different ID. It does not make a key safe: anyone holding the private key can authorize a valid signature, and a valid signature says nothing about whether the requested contract call is benign.

Before execution, a client recovers the sender from the signature and checks the transaction's encoding, chain ID, nonce, intrinsic gas, fee constraints, and sender's ability to cover both value and the maximum gas exposure. The nonce must match the next executable account nonce. A transaction with a future nonce may remain queued locally; that is a client mempool policy, not evidence that the chain accepted it. Different nodes can have different pending pools and inclusion order.

Once a block candidate is executed, each transaction reads from the state produced by earlier transactions in that block. A successful call commits its permitted state changes and emits a receipt. A reverting call rolls back its call-level state changes and logs, but the transaction itself still consumes gas and advances the sender nonce when included. The execution client calculates the block's post-state root. The consensus layer selects the canonical block and later finalizes checkpoints; an RPC response such as eth_call, a local simulation, or a mempool acknowledgement is not finality.

EIP-1559 fee calculation and worked example

For a type-2 transaction, the block base fee and sender's fee caps determine the effective gas price:

Peffective=min⁡(Pmax,Pbase+Ptip),F=GusedPeffectiveP_{\text{effective}}=\min(P_{\text{max}},P_{\text{base}}+P_{\text{tip}}),\qquad F=G_{\text{used}}P_{\text{effective}}

Here, PeffectiveP_{\text{effective}} is the price actually charged per unit of gas, PmaxP_{\text{max}} is maxFeePerGas, PbaseP_{\text{base}} is the block base fee, and PtipP_{\text{tip}} is the capped priority fee. GusedG_{\text{used}} is gas reported by the receipt and FF is the transaction fee. With prices in gwei and gas in units, their product is gwei; divide by 10910^9 to get ETH.

Suppose a wallet submits a transfer of 0.100 ETH with a 100,000 gas limit, maxFeePerGas of 40 gwei, and maxPriorityFeePerGas of 2 gwei. If the included block's base fee is 30 gwei and execution uses 52,000 gas, then the effective price is 32 gwei. The fee calculation is:

52,000×32=1,664,000 gwei=0.001664 ETH52{,}000 \times 32 = 1{,}664{,}000\text{ gwei} = 0.001664\text{ ETH}

The sender must initially cover the transferred value plus maximum gas exposure. At the cap, 100,000 gas multiplied by 40 gwei per gas is 4,000,000 gwei, or 0.004 ETH, so the pre-execution balance check requires at least 0.104 ETH. If the sender began with 1.250 ETH and no other effects apply, the post-state sender balance is 1.148336 ETH. The unused gas limit is not charged at the fee cap.

The base-fee portion is burned under EIP-1559 and the priority-fee portion is paid to the block proposer. A wallet should show the expected fee and maximum required balance separately so that a user does not mistake a cap for the final charge.

The receipt fee is a measurement after execution, not a guarantee made by the wallet's estimate. State changes between simulation and inclusion can alter the work: a storage slot may be warm or cold, a branch may differ, or a call may revert. Compare the receipt's gas used and effective price with the wallet's estimate, while checking that the resulting account and contract storage values match the intended transition.

Sign typed transaction
Validate chain nonce and fee bounds
Execute against block pre-state
Update account and storage tries
Commit state root and finalize block
Conceptual teaching model synthesized from:ethereum-yellow-paper,ethereum-execution-specs,eip-1559

Implementation example

This short TypeScript program decodes a signed EIP-1559 transaction with ethers v6, checks that its signature and network match the intended chain, and computes the maximum fee exposure. It inspects the signed envelope only: a node still has to validate current nonce, balance, base fee, and execution against live state.

typescript
import { Transaction } from "ethers";
​
const raw = process.argv[2];
if (!raw) throw new Error("pass a signed serialized transaction as argv[2]");
​
const transaction = Transaction.from(raw);
if (!transaction.signature || !transaction.from) {
throw new Error("transaction is not signed");
}
if (transaction.type !== 2) {
throw new Error("expected an EIP-1559 type-2 transaction");
}
if (transaction.chainId !== 1n) {
throw new Error(`refusing transaction for chain ${transaction.chainId}`);
}
if (transaction.maxFeePerGas === null) {
throw new Error("transaction has no maximum fee cap");
}
​
const maximumFeeWei = transaction.gasLimit * transaction.maxFeePerGas;
console.log({
hash: transaction.hash,
sender: transaction.from,
nonce: transaction.nonce,
gasLimit: transaction.gasLimit.toString(),
maximumFeeWei: maximumFeeWei.toString(),
});

Failure modes and misconceptions

A valid signature does not prove that the transaction is safe or even that it will execute. A wrong chain ID prevents the intended network from accepting it; an old nonce is stale; a gap can leave the transaction queued; insufficient balance fails admission; and a reverted call can still consume gas. After a reorganization, a previously included transaction may return to a pending pool or be replaced by a competing canonical block.

Do not treat a transaction hash as a state proof. A hash identifies the signed envelope. To establish what happened, inspect the canonical receipt, block hash and number, status, gas accounting, relevant logs, and the state at the block's root. For a high-value action, wait for the product's explicit confirmation policy and use a trusted node or verify a state proof against the expected root.

Trade-offs

The state root gives a compact commitment that supports authenticated reads, but verifying a value requires the right trie nodes and proof rules. A local node can answer reads quickly yet becomes an operational dependency; a remote RPC reduces infrastructure but exposes query metadata and must be trusted or independently checked. A public transaction pool is permissionless and composable, but exposes transactions before inclusion and can invite reordering or failed inclusion. Private submission changes visibility and builder assumptions; it does not remove the need to inspect canonical state.

Fee caps let a sender bound price exposure while the base fee changes block by block. A cap set too low may delay inclusion; a very high cap does not mean that amount is charged, but it increases the balance required for admission. Wallet estimates are useful for UX, while receipt values and block state are the authoritative record after inclusion.

Decision scenario

A treasury dashboard reports that a 0.10 ETH payment succeeded because an RPC returned a transaction hash. A later status poll sees no receipt, and the sender has a pending nonce gap. Do not mark the transfer settled or submit a blind duplicate. Query the transaction and sender nonce on the intended chain, determine whether the transaction is pending, replaced, reverted, or absent, then wait for inclusion and the configured finality threshold. Reconcile the canonical receipt and recipient balance before updating the ledger.

Learning outcomes

  • Describe how a typed signature, chain ID, nonce, fee caps, and current account state gate transaction execution.
  • Calculate an EIP-1559 effective gas price, fee, and maximum balance exposure from units.
  • Explain how execution updates account and storage tries and why the block state root differs from a transaction hash.
  • Separate local simulation, mempool acceptance, block inclusion, canonicality, and consensus finality.
Reflect before revealing the guide

Prerequisites & Related Concepts (1)

Private notes

0 words
Included In Free Course
Free · Verifiable Credential

FS-502Blockchain & Decentralized AI Systems Engineer

Master blockchain execution, consensus, smart contract security, rollups, zkML verification, and safe on-chain AI agent protocols.

10 concepts~24h self-paced
Start Free Course
Weekly Engineering Dispatch

Get the weekly systems teardown

One technical note per week covering inference bottlenecks, retrieval harnesses, and commit-pinned teardowns.

Next