tower-observationcreate_async_public_client

Create async Web3 instance with public (read-only) Seismic access

Create an asynchronous AsyncWeb3 instance with public (read-only) Seismic access.

Overview

create_async_public_client() creates an async client for read-only operations on the Seismic network. No private key is required. The w3.seismic namespace provides only public read operations: get_tee_public_key(), get_deposit_root(), get_deposit_count(), and contract() (with .tread only).

Supports both HTTP and WebSocket connections for efficient async queries and real-time monitoring.

Signature

def create_async_public_client(
    provider_url: str,
    *,
    ws: bool = False,
) -> AsyncWeb3

Parameters

Parameter
Type
Required
Description

provider_url

str

Yes

HTTP(S) or WS(S) URL of the Seismic node

ws

bool

No

If True, uses WebSocketProvider (persistent connection, supports subscriptions). Otherwise uses AsyncHTTPProvider. Default: False. WebSocket is only available on async clients — sync clients are HTTP-only

Returns

Type
Description

AsyncWeb3

An AsyncWeb3 instance with w3.seismic namespace attached (AsyncSeismicPublicNamespace)

Examples

Basic Usage (HTTP)

WebSocket Connection

Using Chain Configuration

Async Application

Read-Only Contract Access

Monitoring Pattern

Parallel Queries

Context Manager Pattern

How It Works

The function performs three steps:

  1. Create provider

  2. Create AsyncWeb3 instance

  3. Attach public Seismic namespace

No TEE public key fetching or encryption setup is performed since the client cannot perform shielded operations.

Client Capabilities

Standard AsyncWeb3 Methods (e.g. w3.eth, w3.net)

  • await get_block(), await get_transaction(), await get_balance()

  • await call(), await estimate_gas()

  • All other standard read-only async web3.py functionality

Public Seismic Methods (w3.seismic)

NOT Available

HTTP vs WebSocket

Aspect

AsyncHTTPProvider (ws=False)

WebSocketProvider (ws=True)

Connection

New connection per request

Persistent connection

Latency

Higher per-request overhead

Lower latency

Subscriptions

Not supported

Supported (eth.subscribe)

Resource usage

Lower idle usage

Keeps connection open

Use case

One-off queries

Real-time monitoring, subscriptions

Notes

  • The function is synchronous (no await needed) but returns an AsyncWeb3 instance whose methods are async

  • No private key required or accepted

  • No encryption setup performed

  • No RPC calls during client creation (lightweight)

  • Cannot perform any write operations or shielded reads

  • Contract wrappers only expose .tread (transparent read, async)

  • All w3.seismic methods are async and must be await-ed

  • WebSocket connections should be properly closed when done

  • For write operations, use create_async_wallet_client()

  • For sync operations, use create_public_client()

Use Cases

  • Async block explorers and chain analytics

  • Real-time monitoring dashboards with WebSocket subscriptions

  • High-throughput read-only services

  • Async data aggregation pipelines

  • Event monitoring and alerting systems

  • Price oracles with low-latency requirements

Warnings

  • Connection cleanup - Close WebSocket connections properly to avoid resource leaks

  • Error handling - WebSocket connections can drop; implement reconnection logic for production

  • HTTPS/WSS recommended - Use secure protocols in production to prevent MITM attacks

See Also

Last updated