eyeEvent Watching

Watch and decrypt SRC20 Transfer and Approval events

Watch SRC20 Transfer and Approval events with automatic decryption of encrypted amounts.

Overview

SRC20 tokens emit Transfer and Approval events with encrypted amounts. The event watching system provides tools to:

  • Poll for SRC20 events matching your viewing key

  • Automatically decrypt encrypted amounts using AES-256-GCM

  • Invoke callbacks with fully decoded event data

  • Handle both sync (threading) and async (asyncio) execution models

Quick Start

Watch Your Own Events

import os
from seismic_web3 import create_wallet_client, PrivateKey
from seismic_web3.src20 import watch_src20_events

private_key = PrivateKey.from_hex_str(os.environ["PRIVATE_KEY"])
w3 = create_wallet_client("https://gcp-1.seismictest.net/rpc", private_key=private_key)

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

# Later...
watcher.stop()

Watch with Explicit Key

Factory Functions

High-level functions that create and start watchers:

Function
Description

Watch with automatic key fetching (sync)

Watch with explicit viewing key (sync)

Both have async variants (async_watch_src20_events, async_watch_src20_events_with_key).

Watcher Classes

Low-level classes for advanced use cases:

Class
Description

Thread-based watcher (sync)

Task-based watcher (async)

Event Types

Decoded event data structures:

Type
Description

Transfer event with decrypted amount

Approval event with decrypted amount

How It Works

  1. Key hash filtering - Events are filtered by keccak256(viewing_key) in the event topics

  2. Polling - The watcher polls eth_getLogs at a configurable interval

  3. Decryption - Encrypted amounts are decrypted using AES-256-GCM with the viewing key

  4. Callbacks - User callbacks are invoked with fully decoded event data

Sync vs Async

Sync (Threading)

  • Runs in a background daemon thread

  • Uses Web3 (synchronous)

  • Callbacks are regular functions

  • Good for scripts and simple applications

Async (asyncio)

  • Runs as an asyncio.Task

  • Uses AsyncWeb3 (asynchronous)

  • Callbacks can be async or sync functions

  • Good for async applications and WebSocket connections

Common Patterns

Context Manager

Error Handling

Filter by Token

Historical Events

See Also

Last updated