# erc20Allowence - EVM Data Stream

> Stream decoded ERC-20 Approval (allowance) events filtered by token, owner, and spender. Complete guide on how to use the erc20Allowence topic in GetBlock EVM Data Stream documentation.

The `erc20Allowence` topic sends one notification per ERC-20 `Approval` event: an owner granting, changing, or revoking a spender's allowance. Use it for approval alerts, risk monitoring, and allowance dashboards.

> **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).

> **Danger:** `erc20Allowence` is the current public topic name, including the misspelling. Send it exactly as shown.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `filters.tokenContract` | string | No | Token contract address. |
| `filters.from` | string | No | Allowance **owner**: the address granting the approval. |
| `filters.to` | string | No | Allowance **spender**: the address being approved. |

The filter names `from` and `to` are reused from `erc20Transfers`: `from` is the owner and `to` is the spender.

## 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":"erc20Allowence","filters":{"from":"0x709c9dffb1e7e37aa62950048328d5c17354a7aa"}}]}
```

#### 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: 'erc20Allowence',
      filters: {
        from: '0x709c9dffb1e7e37aa62950048328d5c17354a7aa'
      }
    }]
  }));
});

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;
  const revoked = BigInt(data.value) === 0n;
  console.log(removed ? 'REVERTED' : revoked ? 'revoked' : 'approved', data.tokenContract, 'spender', data.to, data.value);
});
```

#### 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": "erc20Allowence",
                "filters": {
                    "from": "0x709c9dffb1e7e37aa62950048328d5c17354a7aa"
                }
            }]
        }))

        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"]
            revoked = int(data['value'], 16) == 0
            print('REVERTED' if removed else 'revoked' if revoked else 'approved', data['tokenContract'], 'spender', data['to'], data['value'])

asyncio.run(main())
```

## Response Example

The first reply is the subscription ID:

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

Every later message is an event notification:

```json
{
  "jsonrpc": "2.0",
  "method": "getblock_subscribe",
  "params": {
    "subscription": "0x573e3382e8ea7d534f267b232aae22dd",
    "result": {
      "eventId": "eth:mainnet:receipts:0x19ddc6864bd5ec1cdbd493e3d3653b529d79293a677…",
      "removed": false,
      "revision": 116876401,
      "data": {
        "tokenContract": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
        "from": "0x709c9dffb1e7e37aa62950048328d5c17354a7aa",
        "to": "0xe09ad398e1deee1f18fec1255c58d3dff57068a3",
        "value": "0x3938700",
        "blockNumber": "0x18d1e1e",
        "transactionHash": "0x8a31cb937fb624bae016a3c73389f4596e82150a159b017d54ad3e18c039cc4f",
        "transactionIndex": "0x7",
        "blockHash": "0x19ddc6864bd5ec1cdbd493e3d3653b529d79293a6773517018153cdff6ac0be2",
        "blockTimestamp": "0x6ab110c3",
        "logIndex": "0x14",
        "removed": false
      }
    }
  }
}
```

## 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.tokenContract` | string | ERC-20 token contract address. |
| `data.from` | string | Owner: the address that granted the allowance. |
| `data.to` | string | Spender: the address allowed to spend. |
| `data.value` | string | New allowance in the token's smallest unit, hex-encoded. `0x0` is a revocation; `0xff…ff` (2^256 − 1) is an unlimited approval. |
| `data.address` | string | Address of the contract that emitted the log. |
| `data.blockNumber` | string | Block number, hex-encoded. |
| `data.blockHash` | string | Hash of the block that contains the log. |
| `data.blockTimestamp` | string | Block timestamp in Unix seconds, hex-encoded. |
| `data.transactionHash` | string | Hash of the transaction that emitted the log. |
| `data.transactionIndex` | string | Transaction's position in the block, hex-encoded. |
| `data.logIndex` | string | Log's position in the block, hex-encoded. |
| `data.removed` | boolean | The underlying log's `removed` flag. Use the envelope's `removed` for reorg handling. |

`value` is the new allowance, not an increment. Tokens that support `permit` (EIP-2612) also emit `Approval`, so gasless approvals appear here too.

## Use Cases

* Alerting users when their wallet grants an unlimited approval
* Flagging approvals to known malicious spenders
* Keeping an allowance dashboard or revoke tool up to date
* Detecting that a user approved your contract so your UI can move to the next step

## Error Handling

| Code | Message | Cause |
| --- | --- | --- |
| `-32602` | `invalid tokenContract: invalid EVM address "…"` | `tokenContract` is not a 20-byte hex address. |
| `-32602` | `invalid from: invalid EVM address "…"` | `from` is not a 20-byte hex address. |
| `-32602` | `invalid to: invalid EVM address "…"` | `to` is not a 20-byte hex address. |
| `-32602` | `invalid erc20Allowence 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. |
