Skip to content

Pool

The three methods that remove transactions from the node’s pool before they are mined: one transaction, every transaction of a sender, or all of them.

Method JSON-RPC Returns Description
dropTransaction anvil_dropTransaction Hash | null Removes a transaction from the pool.
dropAllTransactions anvil_dropAllTransactions null Removes every transaction from the pool.
removePoolTransactions anvil_removePoolTransactions null Removes the transactions of one sender from the pool.

Each returns an Effect<…, Method.Error, Transport>. A transaction only waits in the pool when the node does not mine it at once: turn automine off with Anvil.setAutomine(false) first. What is in the pool is read with Txpool.

Removes a transaction from the pool, by hash.

import { Effect } from "effect";
import { Anvil, Eth } from "@ethect/core/rpc";
const dropped = Effect.gen(function* () {
const [from, to] = yield* Eth.accounts();
yield* Anvil.setAutomine(false);
const hash = yield* Eth.sendTransaction({ from, to, value: 1n });
const removed = yield* Anvil.dropTransaction(hash); // the hash
const again = yield* Anvil.dropTransaction(hash); // null
return { removed, again };
});
  • JSON-RPC: anvil_dropTransaction
  • Parameters: hash (Hash).
  • Returns: Hash | null. The hash of the transaction removed, or null when the pool does not hold it, which is also the answer for a transaction that is mined already.
  • The later transactions of the same sender, which waited on its nonce, are removed with it.

Removes every transaction from the pool.

import { Effect } from "effect";
import { Anvil, Eth, Txpool } from "@ethect/core/rpc";
const emptied = Effect.gen(function* () {
const [from, to] = yield* Eth.accounts();
yield* Anvil.setAutomine(false);
yield* Eth.sendTransaction({ from, to, value: 1n });
yield* Anvil.dropAllTransactions();
return yield* Txpool.status(); // { pending: 0, queued: 0 }
});
  • JSON-RPC: anvil_dropAllTransactions
  • Parameters: none.
  • Returns: null, also when the pool was empty.

Removes the transactions of one sender from the pool, and leaves those of the others.

import { Effect } from "effect";
import { Anvil, Eth, Txpool } from "@ethect/core/rpc";
const cleared = Effect.gen(function* () {
const [first, second] = yield* Eth.accounts();
yield* Anvil.setAutomine(false);
yield* Eth.sendTransaction({ from: first, to: second, value: 1n });
yield* Eth.sendTransaction({ from: second, to: first, value: 1n });
yield* Anvil.removePoolTransactions(first!); // anvil always has a first account
return yield* Txpool.status(); // { pending: 1, queued: 0 }
});
  • JSON-RPC: anvil_removePoolTransactions
  • Parameters: address (Address.Address), the sender.
  • Returns: null.
  • Gone, not mined. A removed transaction is no longer known to the node: Eth.getTransactionByHash returns null for it.
  • The nonce is free again. The pending transaction count of the sender goes back down, so the next transaction it sends takes the nonce of the one removed.