---
eip: 2031
label: EIP-2031
title: State Rent B - Net transaction counter
status: Stagnant
type: Standards Track
category: Core
created: 2019-05-15
requires: 2029
official: https://eips.ethereum.org/EIPS/eip-2031
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2031.md
canonical: https://eips.huatuo.xyz/eip-2031/
lang: en
tldr: "Part of the State Rent plan: keep a global count of transactions in a system contract, so accounts evicted by rent and later revived can get a fresh, replay-safe nonce."
tags: [state-rent, nonce, replay-protection, core, state]
---

# EIP-2031: State Rent B - Net transaction counter

> Ethereum starts to track the number of transactions inside its state (for now, only number of transactions after this change is introduced, therefore it is called Net transaction count). It is done by incrementing a storage slot in the special contract, called State counter contract (EIP-2029).

**TL;DR:** Part of the State Rent plan: keep a global count of transactions in a system contract, so accounts evicted by rent and later revived can get a fresh, replay-safe nonce.

## What problem does it solve?

Around 2019 Ethereum researchers explored **state rent**: accounts would pay over time for the state they occupy, and accounts that stop paying could be evicted. That creates a replay problem. If an evicted account is brought back by someone sending it ether, it would start again with nonce 0. Every transaction it signed in the past, with nonces 0, 1, 2…, could then be replayed.

EIP-2031 ("State Rent B") gives a way to pick a starting nonce that is guaranteed to be higher than any nonce the account has used before.

## How it works

- [EIP-2029](/eip-2029/) ("State Rent A") introduces a special **state counter contract** that holds global counters in its storage.
- EIP-2031 adds `txCount` at **storage slot 0** of that contract. It can be read by calling the contract with 32 zero bytes as input.
- From fork block B (or the deployment of the counter contract, whichever comes first), `txCount` is incremented after **every** transaction. These updates are never reverted, even if the transaction itself fails.
- Because it only counts transactions after activation, it is called the *net* transaction counter.
- The counter is then used to set the nonce of newly created non-contract accounts, including evicted accounts that are recreated. No account can have sent more transactions than the global total, so a nonce taken from `txCount` cannot collide with an old one.

The spec also considers two alternatives and rejects them:

1. A `valid-until` field on transactions, which keeps nonces at 0 but conflicts with nonces being used to derive `CREATE` contract addresses.
2. A nonce derived from the block number, which needs an arbitrary cap on transactions per block.

## Sample code

Pseudocode for the state transition:

```python
STATE_COUNTER_CONTRACT = ...   # defined by EIP-2029
TX_COUNT_SLOT = 0

def apply_transaction(state, tx):
    result = execute(state, tx)           # may succeed or fail
    n = state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT)
    state.set_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT, n + 1)  # never reverted
    return result

def create_account(state, address):
    state.accounts[address] = Account(
        nonce=state.get_storage(STATE_COUNTER_CONTRACT, TX_COUNT_SLOT),
        balance=0,
    )
```

## Things to know

- **Status: Stagnant**, like the rest of the State Rent series ([EIP-2029](/eip-2029/), [EIP-2027](/eip-2027/), [EIP-2026](/eip-2026/)).
- It would have required a hard fork. The block number B was never set.
- State rent was not adopted on Ethereum. Research into state growth moved to other directions such as statelessness and state expiry.
- Even if revived, the spec was preliminary: test cases and a reference implementation were still listed as future work.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2031
