Skip to main content
Leafage reads on-chain state at a specified chain and block. Run these examples in a Chaintable Notebook. For Function usage, see Data access. The source contains the full implementation.

Create a block context

ChainState(chain_id, block_id)

Returns a ChainState object. For consistent multiple reads, first resolve a block ID and then reuse the same object.

Block queries

These are class methods, called directly on ChainState. Block dictionaries include id, height, and timestamp. timestamp is Unix time in seconds. Additional fields may vary by chain.

Account state

get_address_nonce() uses the latest block, so it does not return a historical nonce from the chain object’s context. The other three instance methods use that object’s block context.

Single contract call

chain.call(contract, method, payload, from_addr=None)

Returns decoded values. Multiple outputs can be unpacked; integers are Python int values.
This reads or simulates a contract call. It does not send a transaction to the chain.

Batch contract calls

The output is ['USDC', 6]. For example, replace .values() with .dict('symbol', 'decimals') to get {'symbol': 'USDC', 'decimals': 6}.

State overrides

set_block_overrides(value) and set_state_overrides(value) set block and account-state overrides for simulated calls. The corresponding get_*_overrides() methods return current settings. Overrides affect simulated reads without changing on-chain state. See the Leafage source for field definitions and full examples.