book-openPublicContract

Sync contract wrapper with transparent read-only access

Synchronous contract wrapper for read-only transparent access to Seismic contracts.

Overview

PublicContract provides a simplified interface for reading public contract state without requiring encryption or a private key. It exposes only the .tread namespace for standard eth_call operations. Use this class when you only need to read public contract data and don't need shielded operations.

Definition

class PublicContract:
    def __init__(
        self,
        w3: Web3,
        address: ChecksumAddress,
        abi: list[dict[str, Any]],
    ) -> None:
        ...

Constructor Parameters

Parameter
Type
Required
Description

w3

Web3

Yes

Synchronous Web3 instance connected to RPC endpoint

address

ChecksumAddress

Yes

Contract address (checksummed Ethereum address)

abi

list[dict[str, Any]]

Yes

Contract ABI (list of function entries)

Namespace

.tread - Transparent Read

Executes standard eth_call with unencrypted calldata. This is the only namespace available on PublicContract.

Returns: HexBytes (raw result bytes)

Optional Parameters: None (pass positional arguments only)

Examples

Basic Read Operations

Decoding Results

Multiple Reads

Complex Return Types

Array Results

Instantiation via Client

Checking Contract State

Pagination Pattern

View Functions Only

Error Handling

With Custom RPC

Notes

  • Read-only: No write operations available (no .write, .twrite, or .dwrite namespaces)

  • No encryption required: Does not use EncryptionState or private keys

  • No authentication: Standard unsigned eth_call operations

  • View functions only: Can only call view or pure functions

  • Gas not consumed: eth_call is free (doesn't create transactions)

  • No state changes: Cannot modify blockchain state

  • Public data only: Cannot access shielded/encrypted contract state

  • ABI remapping: Same ABI type remapping as ShieldedContract

  • Dynamic methods: Contract methods resolved via __getattr__

Use Cases

Public Data Queries

Perfect for:

  • Querying ERC-20 token balances

  • Reading public contract configuration

  • Checking access control roles

  • Viewing public state variables

  • Aggregating data from multiple contracts

  • Building read-only dashboards

  • Monitoring contract state

When to Use ShieldedContract Instead

Use ShieldedContract when you need:

  • Write operations (state changes)

  • Encrypted reads of shielded state

  • Authenticated operations

  • Transaction signing

  • Access to private/shielded data

See Also

Last updated