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
Watch with automatic key fetching from Directory
Watch with an explicit viewing key
Both have async variants (async_watch_src20_events, async_watch_src20_events_with_key).
Watcher Classes
Thread-based polling watcher (sync)
Task-based polling watcher (async)
Example
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
Key hash —
keccak256(viewing_key)is used to filter events by the 4th topicPolling —
eth_getLogsat a configurable interval (default 2s)Decryption — AES-256-GCM with the viewing key (no AAD)
Callbacks — invoked with
DecryptedTransferLogorDecryptedApprovalLog
See Also
Types — Decrypted event data structures
Intelligence Providers — Viewing key management
Last updated

