# Event Watching

SRC20 tokens emit Transfer and Approval events with encrypted amounts. The event watching system polls for these events, decrypts them using your viewing key, and invokes callbacks with decoded data.

## Factory Functions

| Function                                                                                                       | Description                                      |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| [watch\_src20\_events](/clients/python/src20/event-watching/watch-src20-events.md)                             | Watch with automatic key fetching from Directory |
| [watch\_src20\_events\_with\_key](/clients/python/src20/intelligence-providers/watch-src20-events-with-key.md) | Watch with an explicit viewing key               |

Both have async variants (`async_watch_src20_events`, `async_watch_src20_events_with_key`).

## Watcher Classes

| Class                                                                                       | Description                         |
| ------------------------------------------------------------------------------------------- | ----------------------------------- |
| [SRC20EventWatcher](/clients/python/src20/event-watching/src20-event-watcher.md)            | Thread-based polling watcher (sync) |
| [AsyncSRC20EventWatcher](/clients/python/src20/event-watching/async-src20-event-watcher.md) | Task-based polling watcher (async)  |

## Example

```python
import os
from seismic_web3 import PrivateKey, SEISMIC_TESTNET
from seismic_web3.src20 import watch_src20_events

pk = PrivateKey.from_hex_str(os.environ["PRIVATE_KEY"])
w3 = SEISMIC_TESTNET.wallet_client(pk)

watcher = watch_src20_events(
    w3,
    encryption=w3.seismic.encryption,
    private_key=pk,
    on_transfer=lambda log: print(f"Transfer: {log.decrypted_amount}"),
    on_approval=lambda log: print(f"Approval: {log.decrypted_amount}"),
)

# Later...
watcher.stop()
```

## How It Works

1. **Key hash** — `keccak256(viewing_key)` is used to filter events by the 4th topic
2. **Polling** — `eth_getLogs` at a configurable interval (default 2s)
3. **Decryption** — AES-256-GCM with the viewing key (no AAD)
4. **Callbacks** — invoked with [`DecryptedTransferLog`](/clients/python/src20/types/decrypted-transfer-log.md) or [`DecryptedApprovalLog`](/clients/python/src20/types/decrypted-approval-log.md)

## See Also

* [Types](/clients/python/src20/types.md) — Decrypted event data structures
* [Intelligence Providers](/clients/python/src20/intelligence-providers.md) — Viewing key management


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seismic.systems/clients/python/src20/event-watching.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
