Sub topic 8
The life of a transaction
This chapter follows one transfer from the moment you press "Send" until it is final. It assumes you know what a private key, an address, a nonce and gas are, from the earlier chapters. The examples use the account model with Ethereum-style terms. Other networks differ in detail but follow the same overall path.
The big picture
A transaction is a signed instruction. It is not a coin that moves. Nothing changes on the network until a block producer includes your instruction in a block and the network accepts that block.
The path has six stages: build, sign, broadcast, wait in the mempool, get included in a block, and become final.
Stage 1: Build the transaction
Your wallet or library fills in the fields of the transaction. For a basic Ethereum-style transfer these are:
| Field | Meaning |
|---|---|
| `to` | The recipient address, or a token contract address for token transfers |
| `value` | Amount of native coin to send, in the smallest unit (wei) |
| `nonce` | The sender's transaction counter, which fixes the order |
| `gasLimit` | The most gas you allow the transaction to use |
| `maxFeePerGas` and `maxPriorityFeePerGas` | The most you will pay per unit of gas, and the tip to the block producer |
| `chainId` | Which network the transaction is valid on |
| `data` | Empty for a plain transfer, or an encoded contract call |
Most of these are estimated for you. The library asks the node for the next nonce, a gas estimate and current fee levels. The chainId matters for safety: it is part of what you sign, so a transaction signed for one network cannot be replayed on another.
Stage 2: Sign
Signing turns the fields into proof that the account owner approved them. Your wallet hashes the transaction fields and signs the hash with your private key. The private key never leaves the wallet and is never part of the transaction.
Anyone can check the signature against the sender's public key. The sender address is recovered from the signature, which is why the transaction has no separate "from" field. The transaction hash, the ID you see in explorers, is computed from the signed data. So you know the hash before the network has seen the transaction.
Any change to a field after signing invalidates the signature. That is why a "speed up" action creates a new signed transaction instead of editing the old one.
Stage 3: Broadcast
The signed transaction goes to a node, usually through a JSON-RPC endpoint. This is the RPC URL your wallet or code is configured with. The node checks the basics:
- The signature is valid.
- The nonce is not lower than the account's current nonce.
- The account can afford
valueplus the maximum possible fee (gasLimittimesmaxFeePerGas). - The gas limit and fee settings meet the node's minimums.
If a check fails, the node rejects the transaction immediately with an error, and nothing is queued. If the checks pass, the node returns the transaction hash and gossips the transaction to its peers.
A returned hash means the node accepted the transaction for relay. It does not mean the transaction is in a block.
Stage 4: Pending in the mempool
Each node keeps a mempool, a waiting area of valid transactions that are not yet in a block. There is no single global mempool. Each node has its own view, and views differ slightly depending on what has reached them.
Block producers pick transactions from the mempool, mostly in order of how much they pay per unit of gas. Two rules shape the wait:
- Fee competition. If your fee is below what is currently being included, you wait. When the network is busy, that can take a long time.
- Nonce order. Transactions from one account must run in nonce order. If you send nonce 7 while nonce 6 is missing or pending, nonce 7 waits behind it, however high its fee.
A pending transaction can leave the mempool in three ways. It can be included in a block. It can be replaced by another transaction with the same nonce and a sufficiently higher fee. Or it can be dropped, for example because nodes limit mempool size or because the account no longer has enough balance. A dropped transaction was never executed, so no funds moved.
Stage 5: Inclusion and execution
A block producer takes your transaction and includes it in a block. When the block is processed, the network executes the transaction:
- It checks the nonce and deducts the maximum fee up front.
- It moves
valuefrom sender to recipient, or runs the contract code indata. - It measures the gas actually used, refunds unused gas, and sends the tip to the block producer. On networks with a base fee, the base fee is burned.
- It records the result in a receipt.
Inclusion and success are separate facts. A transaction can be included and still fail, for example when a contract call reverts. In that case the state changes from the call are undone, but the gas used is still charged, because the network did the work. The receipt status tells you which happened: 1 for success, 0 for failure.
The receipt also holds the block number, the gas used, the effective gas price, and any event logs. Token transfers appear as logs, which is how wallets and explorers know a token arrived.
Stage 6: More blocks, then finality
Being in one block is not the end. The most recent blocks can be replaced if the network briefly disagrees about which chain is correct. Each new block built on top of yours is one more confirmation, and reorganizing becomes less likely. The next chapter covers confirmations and finality in detail. For now, treat "included" and "final" as different states.
Watching a transaction in code
This example uses ethers v6. It separates the stages so you can see where your transaction is. Use a testnet and a throwaway key.
import { JsonRpcProvider, Wallet, parseEther } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const wallet = new Wallet(process.env.PRIVATE_KEY, provider);
// Stages 1-3: build, sign, broadcast. The library does all three.
const tx = await wallet.sendTransaction({
to: "0x0000000000000000000000000000000000000001",
value: parseEther("0.01"),
});
console.log("Accepted by node:", tx.hash, "nonce", tx.nonce);
// Stage 4: right after sending, the transaction is usually pending.
const seen = await provider.getTransaction(tx.hash);
console.log("In a block yet?", seen && seen.blockNumber !== null);
// Stage 5: wait for inclusion with 1 confirmation.
const receipt = await tx.wait(1);
console.log("Included in block", receipt.blockNumber);
console.log("Status:", receipt.status === 1 ? "success" : "failed");
console.log("Gas used:", receipt.gasUsed.toString());
// Stage 6: count blocks on top of ours.
const head = await provider.getBlockNumber();
console.log("Confirmations:", head - receipt.blockNumber + 1);getTransaction returns null if the node has never seen the hash, and its blockNumber is null while the transaction is pending. Check for both, as the code does.
What can go wrong at each stage
| Stage | Typical problem | What you see |
|---|---|---|
| Build | Wrong network or wrong asset selected | Funds go somewhere you did not intend |
| Sign | Wallet connected to the wrong account | The sender balance is too low |
| Broadcast | Insufficient funds, nonce too low, fee below minimum | An immediate error from the node |
| Mempool | Fee too low, or an earlier nonce is stuck | Pending for a long time |
| Inclusion | Contract call reverts, or gas limit too low | Status `0`, gas still spent |
| Finality | A short reorganization | The block disappears, and the transaction goes back to pending or is dropped |
Two points are easy to misread. First, a "failed" transaction on a block explorer still cost money, and your nonce was still used. Second, an error at broadcast is different from a failure at inclusion: the first means the network never accepted it, and the second means it ran and was charged.
Practical rules from the lifecycle
- Record the hash and nonce of every important transaction.
- Judge success by the receipt status, not by the hash returned at broadcast.
- Do not treat a payment as complete until it has the confirmations that fit its value.
- When a transaction is pending, check its nonce and fee before sending anything new from the same account.
Exercise
You send a token transfer and your library returns a transaction hash at once. A minute later the explorer shows the transaction as included, with status 0 (failed). Was any money lost, and has the token moved? Explain using the stages above.
Show answer
The token did not move, because a status of 0 means the execution reverted and its state changes were undone. You still lost money: the gas used was charged in the native coin, and the nonce was consumed. The hash returned at broadcast only showed that the node accepted the transaction for relay. It said nothing about the execution result, which is only known from the receipt after inclusion.
Exercise
Your account has a pending transaction with nonce 12 and a very low fee. You then send nonce 13 with a very high fee. Which one is confirmed first, and why?
Show answer
Nonce 12 is confirmed first, and nonce 13 cannot be included until it is. Transactions from one account run in nonce order, so the high fee on nonce 13 does not let it skip ahead. To unblock both, replace nonce 12 with a new transaction that has the same nonce and a higher fee.