Skip to content

TransactionPool

The node’s transaction pool, in four shapes: its counts, its transactions in full by sender and nonce, those of one sender, and one line of text per transaction.

import { Effect } from "effect";
import { Txpool } from "@ethect/core/rpc";
const hashes = Effect.gen(function* () {
const pool = yield* Txpool.content();
// pool: TransactionPool.TransactionPool
return Object.values(pool.pending).flatMap((byNonce) =>
Object.values(byNonce).map((transaction) => transaction.hash),
);
});

Every shape has the same two parts. A pending transaction can be mined now. A queued one waits for an earlier nonce of its sender.

Schema Type Describes Returned by
TransactionPool.statusSchema TransactionPool.Status how many transactions each part holds Txpool.status
TransactionPool.schema TransactionPool.TransactionPool every transaction, by sender then by nonce Txpool.content
TransactionPool.fromSchema TransactionPool.From the transactions of one sender, by nonce Txpool.contentFrom
TransactionPool.inspectSchema TransactionPool.Inspect every transaction as a line of text, by sender then by nonce Txpool.inspect

Import a type to name it in your own signatures.

import type { TransactionPool } from "@ethect/core/rpc";
const isEmpty = (status: TransactionPool.Status): boolean =>
status.pending === 0 && status.queued === 0;

Each type is an object with the keys pending and queued. What the two hold depends on the type.

Type pending and queued are each
Status number: a count
TransactionPool Record<Address, Record<string, Transaction>>: sender, then nonce, then the Transaction
From Record<string, Transaction>: nonce, then the Transaction
Inspect Record<Address, Record<string, string>>: sender, then nonce, then a line of text

What anvil 1.9 answers to txpool_inspect with two transfers of one sender waiting, the second with the nonce 5 and nothing before it:

{
"pending": {
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": {
"0": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8: 1 wei + 21000 gas × 2000000000 wei"
}
},
"queued": {
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266": {
"5": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8: 1 wei + 21000 gas × 2000000000 wei"
}
}
}

txpool_status answers {"pending":"0x1","queued":"0x1"} for the same pool.

  • Nonce keys are decimal strings. The nonce 5 is the key "5", not "0x5" and not a number. Read it with byNonce["5"], or go through Object.entries.
  • Sender keys are lowercase addresses. anvil sends them in checksum case, as above, and they are decoded to lowercase like every address. An Address.Address indexes the record directly.
  • A sender with nothing is not a key. An empty part is an empty object, and for Txpool.contentFrom both parts are.
  • Transactions are pending ones. Their blockHash, blockNumber and transactionIndex are null.
  • The text of Inspect reads <to>: <value> wei + <gas> gas × <gas price> wei. It is for a person to read: take figures from TransactionPool, not from the text.
  • Counts are decoded. The node sends the counts of Status as hex quantities and they are decoded to number.