# 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`](#droptransaction) | `anvil_dropTransaction` | `Hash \| null` | Removes a transaction from the pool. |
| [`dropAllTransactions`](#dropalltransactions) | `anvil_dropAllTransactions` | `null` | Removes every transaction from the pool. |
| [`removePoolTransactions`](#removepooltransactions) | `anvil_removePoolTransactions` | `null` | Removes the transactions of one sender from the pool. |

Each returns an [`Effect<…, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method). A
transaction only waits in the pool when the node does not mine it at once: turn automine off
with [`Anvil.setAutomine(false)`](https://ethect.dev/rpc/anvil/mining/#setautomine) first. What is in the
pool is read with [`Txpool`](https://ethect.dev/rpc/txpool/).

## dropTransaction

Removes a transaction from the pool, by hash.

```ts
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`](https://ethect.dev/reference/primitives/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.

## dropAllTransactions

Removes every transaction from the pool.

```ts
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.

## removePoolTransactions

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

```ts
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`](https://ethect.dev/reference/primitives/address/)), the sender.
- **Returns:** `null`.

## Behavior

- **Gone, not mined.** A removed transaction is no longer known to the node:
  [`Eth.getTransactionByHash`](https://ethect.dev/rpc/eth/get-transaction-by-hash/) 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.
