# newPendingTransactions - EVM Data Stream

> Stream pending mempool transactions, as full objects or hashes, filtered by sender and recipient. Complete guide on how to use the newPendingTransactions topic in GetBlock EVM Data Stream documentatio

The `newPendingTransactions` topic sends transactions **observed in the mempool before they are mined**, as full objects or hashes only. Use it to react to transactions before inclusion, such as showing an incoming payment as pending.

> **Warning:** **WebSocket-only topic.** Subscribe with [`getblock_subscribe`](/evm-data-stream/api-reference/getblock_subscribe-evm-data-stream/) on any [network endpoint](/evm-data-stream/api-reference/#endpoints).

> **Info:** Pending transactions are what GetBlock's nodes observe in the public mempool. Transactions sent through private relays never appear here, and a pending transaction may be replaced, dropped, or never mined. Mempool availability depends on the network.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `hashesOnly` | boolean | No | `true` to receive only the transaction hash. Default `false`: the full transaction object. |
| `fromAddress` | string or array | No | Sender address, or an array of senders. |
| `toAddress` | string or array | No | Recipient address, or an array of recipients. |

These fields sit at the **top level** of the request object, not inside `filters`. Address matching is **OR**: a transaction matches if its sender is in `fromAddress` **or** its recipient is in `toAddress`. `fromAddress` and `toAddress` together accept at most 50 addresses.

## Request Example

#### wscat

```bash
# WebSocket-only. Connect first:
wscat -c 'wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream' -H 'Authorization: Bearer <API-KEY>'

# Then send:
{"jsonrpc":"2.0","id":1,"method":"getblock_subscribe","params":[{"topic":"newPendingTransactions","hashesOnly":false,"toAddress":["0xdAC17F958D2ee523a2206206994597C13D831ec7"]}]}
```

#### JavaScript

```javascript
// npm install ws
import WebSocket from 'ws';

const ws = new WebSocket('wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream', {
  headers: { Authorization: 'Bearer <API-KEY>' }
});

ws.on('open', () => {
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'getblock_subscribe',
    params: [{
      topic: 'newPendingTransactions',
      hashesOnly: false,
      toAddress: [
        '0xdAC17F958D2ee523a2206206994597C13D831ec7'
      ]
    }]
  }));
});

ws.on('message', (raw) => {
  const msg = JSON.parse(raw);

  // First reply is the subscription ID (or an error)
  if (msg.id !== undefined) {
    console.log(msg.error ?? `Subscribed: ${msg.result}`);
    return;
  }

  const { removed, data } = msg.params.result;
  // data is the transaction object, or a hash string with hashesOnly
  const hash = typeof data === 'string' ? data : data.hash;
  console.log('pending', hash);
});
```

#### Python

```python
# pip install "websockets>=14"
import asyncio, json, websockets

URL = "wss://stream.eu-central-1.getblock.io/v1/eth-mainnet/stream"
HEADERS = {"Authorization": "Bearer <API-KEY>"}

async def main():
    # ping_interval=None: the server sends its own keepalive pings (see Connection keepalive)
    async with websockets.connect(URL, additional_headers=HEADERS, ping_interval=None) as ws:
        await ws.send(json.dumps({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "getblock_subscribe",
            "params": [{
                "topic": "newPendingTransactions",
                "hashesOnly": False,
                "toAddress": [
                    "0xdAC17F958D2ee523a2206206994597C13D831ec7"
                ]
            }]
        }))

        async for message in ws:
            msg = json.loads(message)

            # First reply is the subscription ID (or an error)
            if "id" in msg:
                print(msg.get("error") or f"Subscribed: {msg['result']}")
                continue

            event = msg["params"]["result"]
            removed, data = event["removed"], event["data"]
            # data is the transaction object, or a hash string with hashesOnly
            tx_hash = data if isinstance(data, str) else data['hash']
            print('pending', tx_hash)

asyncio.run(main())
```

## Response Example

The first reply is the subscription ID:

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0xb804f790318735a54af48a0bd5e2a722"
}
```

Every later message is an event notification:

```json
{
  "jsonrpc": "2.0",
  "method": "getblock_subscribe",
  "params": {
    "subscription": "0xb804f790318735a54af48a0bd5e2a722",
    "result": {
      "eventId": "eth:mainnet:pending_tx:0xe0edbc80b18c6ca13ad9fda66cc84d439df2f07c5…",
      "removed": false,
      "revision": 117006720,
      "data": {
        "blockHash": null,
        "blockNumber": null,
        "blockTimestamp": null,
        "from": "0x559432e18b281731c054cd703d4b49872be4ed53",
        "gas": "0x33450",
        "gasPrice": "0x74ce93d080",
        "maxFeePerGas": "0x74ce93d080",
        "maxPriorityFeePerGas": "0x64414880",
        "hash": "0xe0edbc80b18c6ca13ad9fda66cc84d439df2f07c5fdffed9887d242eb45c0dea",
        "input": "0xa9059cbb000000000000000000000000a7e42c09b68b35f9bf94a7b78384515239d3f3ab0000000000000000000000000000000000000000000000000000000002b5c960",
        "nonce": "0x72da69",
        "to": "0xdac17f958d2ee523a2206206994597c13d831ec7",
        "transactionIndex": null,
        "value": "0x0",
        "type": "0x2",
        "accessList": [],
        "chainId": "0x1",
        "v": "0x0",
        "r": "0x1d5d4283207c53538d4cf8a9b7d7cc5ea879068f461a25bc0865fa463a5806a4",
        "s": "0x1ddaaa9101d2ff821dce7e4b3a670090f0ef42b06c7de6aa35ee33ab9a13174f",
        "yParity": "0x0"
      }
    }
  }
}
```

With `"hashesOnly": true`, `data` is the hash string itself:

```json
{
  "eventId": "eth:mainnet:pending_tx:0x89cdc9983780a9e1c207351f10e35f697a30b0dd54855605e1f7f0e92fd25e15:newPendingTransactions:0x89cdc9983780a9e1c207351f10e35f697a30b0dd54855605e1f7f0e92fd25e15",
  "removed": false,
  "revision": 117081345,
  "data": "0x89cdc9983780a9e1c207351f10e35f697a30b0dd54855605e1f7f0e92fd25e15"
}
```

> **Warning:** The payload shape differs from `newMinedTransactions`. Here `data` **is** the transaction object (or hash string); it is not wrapped in `data.transaction`.

## Response Parameters

The `result` object contains the event envelope and the payload in `data`.

| Field | Type | Description |
| --- | --- | --- |
| `eventId` | string | Stable event identifier. A reorg correction reuses it. |
| `removed` | boolean | `true` when a reorg removed this previously delivered event. |
| `revision` | number | Event version. For one `eventId`, a greater revision is newer. |
| `data` | object or string | The pending transaction, in the same shape as `eth_getTransactionByHash`. With `hashesOnly`, the transaction hash as a string. |
| `data.hash` | string | Transaction hash. |
| `data.from` | string | Sender. |
| `data.to` | string | Recipient. `null` for contract creation. |
| `data.value` | string | Native value in wei, hex-encoded. |
| `data.input` | string | Call data. |
| `data.nonce` | string | Sender nonce, hex-encoded. |
| `data.gas` | string | Gas limit, hex-encoded. |
| `data.gasPrice` | string | Gas price in wei, hex-encoded. Equals `maxFeePerGas` for EIP-1559 transactions. |
| `data.maxFeePerGas` | string | EIP-1559 max fee per gas. |
| `data.maxPriorityFeePerGas` | string | EIP-1559 priority fee per gas. |
| `data.type` | string | EIP-2718 transaction type, hex-encoded. |
| `data.chainId` | string | Chain ID, hex-encoded. |
| `data.accessList` | array | EIP-2930 access list. |
| `data.blockHash, blockNumber, blockTimestamp, transactionIndex` | null | Always `null`: the transaction is not in a block yet. |
| `data.v, r, s, yParity` | string | Signature values. |

## Use Cases

* Showing incoming payments as "pending" before confirmation
* Monitoring your own broadcast transactions for replacement or stalling
* Mempool analytics and gas-price research
* Detecting pending interactions with a contract you operate

## Error Handling

| Code | Message | Cause |
| --- | --- | --- |
| `-32602` | `fromAddress and toAddress exceed the 50-address limit` | More than 50 addresses in total. |
| `-32602` | `invalid toAddress address "…"` | An address is not a 20-byte hex address. The same applies to `fromAddress`. |
| `-32602` | `invalid newPendingTransactions request: json: unknown field "filters"` | The fields were nested in `filters`. Put them at the top level. |
| `-32602` | `invalid newPendingTransactions request: json: unknown field "…"` | The request has a field this topic does not accept. |
| `-32001` | `subscription limit exceeded` | You already have 15 active or pending subscriptions. |
