> For the complete documentation index, see [llms.txt](https://docs.seismic.systems/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seismic.systems/clients/python/src20/event-watching.md).

# Event Watching

Watch and decrypt SRC20 Transfer and Approval events

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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
