eyewatch_src20_events

Watch SRC20 events for your wallet with automatic key fetching

Watch SRC20 Transfer and Approval events for your wallet, automatically fetching the viewing key from the Directory contract.

Overview

watch_src20_events() and async_watch_src20_events() create event watchers that poll for SRC20 events, decrypt the encrypted amounts using your viewing key from the Directory contract, and invoke callbacks with the decrypted data.

The functions automatically:

  • Fetch your viewing key from the Directory contract via signed read

  • Compute the key hash for event filtering

  • Poll for Transfer and Approval events matching your key hash

  • Decrypt encrypted amounts using AES-256-GCM

  • Invoke callbacks with fully decoded event data

Signature

def watch_src20_events(
    w3: Web3,
    *,
    encryption: EncryptionState,
    private_key: PrivateKey,
    token_address: ChecksumAddress | None = None,
    on_transfer: TransferCallback | None = None,
    on_approval: ApprovalCallback | None = None,
    on_error: ErrorCallback | None = None,
    poll_interval: float = 2.0,
    from_block: int | str = "latest",
) -> SRC20EventWatcher

async def async_watch_src20_events(
    w3: AsyncWeb3,
    *,
    encryption: EncryptionState,
    private_key: PrivateKey,
    token_address: ChecksumAddress | None = None,
    on_transfer: AsyncTransferCallback | TransferCallback | None = None,
    on_approval: AsyncApprovalCallback | ApprovalCallback | None = None,
    on_error: AsyncErrorCallback | ErrorCallback | None = None,
    poll_interval: float = 2.0,
    from_block: int | str = "latest",
) -> AsyncSRC20EventWatcher

Parameters

Parameter
Type
Required
Description

w3

Web3 or AsyncWeb3

Yes

Web3 instance with Seismic support

encryption

Yes

Encryption state from wallet client

private_key

Yes

32-byte signing key for signed reads

token_address

ChecksumAddress

No

SRC20 contract to filter. If None, watches all SRC20 tokens

on_transfer

Callback

No

Callback invoked for Transfer events

on_approval

Callback

No

Callback invoked for Approval events

on_error

Callback

No

Callback for errors (decryption failures, RPC errors)

poll_interval

float

No

Seconds between polls (default 2.0)

from_block

int or "latest"

No

Starting block number or "latest" (default)

Returns

Type
Description

Sync watcher (already started)

Async watcher (already started)

Examples

Basic Usage (Sync)

Watch Specific Token

With Context Manager

Error Handling

Historical Events

Async Usage

Async Context Manager

How It Works

  1. Fetch viewing key - Calls the Directory contract's getKey() via signed read to fetch your viewing key

  2. Compute key hash - Calculates keccak256(viewing_key) for event filtering

  3. Create watcher - Instantiates SRC20EventWatcher or AsyncSRC20EventWatcher with the viewing key

  4. Start polling - Begins background polling (thread for sync, task for async)

  5. Process events - For each poll:

    • Fetches logs via eth_getLogs with key hash filter

    • Decodes event topics and data

    • Decrypts encrypted amounts using AES-256-GCM

    • Invokes callbacks with decrypted data

Callback Signatures

Transfer Callback

See DecryptedTransferLog for field details.

Approval Callback

See DecryptedApprovalLog for field details.

Error Callback

Notes

  • The watcher starts automatically upon creation

  • For sync version, polls in a background daemon thread

  • For async version, runs as an asyncio.Task

  • Requires a registered viewing key in the Directory contract

  • Events are only visible if they match your key hash

  • Call .stop() or use context manager to clean up

  • The from_block parameter defaults to "latest" (current block)

Warnings

  • Viewing key required - Raises ValueError if no viewing key is registered in Directory

  • Network connectivity - Polls will fail silently if RPC connection drops (check on_error)

  • Gas costs - This function makes an RPC call to fetch the viewing key

  • Thread safety - Sync version spawns a daemon thread; ensure proper cleanup

  • Memory usage - Keep poll interval reasonable to avoid excessive log fetching

See Also

Last updated