Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Reading state from a client

The sequencer accepts transactions; the indexer answers questions about what happened. A client talks to both, and almost everything an application displays comes from the indexer’s JSON-RPC surface.

Source: lez/indexer/service/rpc/src/lib.rs for the interface, lez/indexer/service/protocol/src/lib.rs for the types.

The surface

Sixteen methods and two subscriptions.

MethodReturns
getAccount(account_id)the account’s full state, or null
getAccountAtBlock(account_id, block_id)the same, as of a height
getAccountSummary(account_id)the nonce, the balance and the size of each actor state, not its bytes. An unknown account returns nonce 0, balance 0 and no actor states, not null; balance is null only when the native state does not decode
getAccountView(actor)the account’s nonce and one program’s actor state, projected out of the account. Takes an Actor (an account id and a program account id) to know which program’s state to return
getAccountViewAtBlock(actor, block_id)the same, as of a height
getBlockById(block_id)a block
getBlockByHash(hash)a block
getBlocks(before, limit)blocks paging backwards from a cursor, newest first; not a range. A limit above 100 is refused with InvalidParams
getTransaction(hash)a transaction
getTransactionReceipt(hash)how it went: success, plus a fee breakdown of execution gas, storage gas, base fee, tip and refund. None for an unknown hash, and for a block’s trailing fee and clock transactions
getTransactionsByAccount(account_id, offset, limit)an account’s transaction history, paged. A limit above 100 is refused with InvalidParams
getEvents(filter)program events; see Events
getLastFinalizedBlockId()the finality watermark; see Finality
getStatus()node status
getSchema()the indexer’s own schema, which is the authoritative shape reference
checkHealth()liveness
SubscriptionStreams
subscribeToFinalizedBlocksblock ids as they become irreversible, not the blocks; fetch a body with getBlockById
subscribeToEvents(filter)EventRecord as events are indexed

The indexer reads finalized L1 blocks, so a transaction already landed on the zone returns null here until its block finalizes, and the indexer can report CaughtUp with nothing indexed. For the answer now, ask the sequencer’s getTransactionReceipt; it answers from its head, which can still change until the block is final (Finality).

Read the receipt rather than inferring an outcome. success is false for a reverted transaction, which is still in its block and still paid, so “absent” and “failed” are different answers. Receipts are covered by the block hash: part of the block, not an indexer annotation. A receipt does not say why a transaction reverted: settlement drops the reason. The wallet library simulates a publicly paid transaction before sending it and refuses one that reverts with ExecutionFailureKind::SimulatedRevert(reason); a dry run reports the same reason (Pricing it first). Both run against the head at that moment, so a transaction that passes and then reverts on chain leaves no reason anywhere.

Call getSchema during development rather than transcribing shapes from this page: it is generated from the server’s own types, so it cannot drift.

A first request

A local indexer listens on port 8779 (Running a node). A call is a JSON-RPC POST; parameters can be positional, and an account id is bare base58, without the wallet’s Public/ prefix:

curl -s http://127.0.0.1:8779 -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"getAccount","params":["7VDm7YRPvimbZgCzuFqCGf6RwPsTV3XY5W9DzT71oain"]}'

The account id above is a sample; use one of yours. The answer is under result, null for an account that does not exist, in the shape below; a failure is still HTTP 200, with an error member instead. This repository publishes no testnet indexer endpoint: the wallet’s testnet network names only the sequencer, https://testnet.lez.logos.co.

The sequencer’s own RPC

The indexer is for history; the sequencer answers about now. A client writing directly against it rather than through the wallet library needs these, none of which the indexer has:

MethodReturns
sendTransaction(tx)submits it, as base64 of its borsh bytes, and returns its hash
getFeeState()the fee market’s current base fees and the band the next block’s can move within, for sizing max_fee
getZoneId()the zone a signature must be for
getChannelId()the L1 channel this zone is written to
getProofsAndRoot(commitments, message_positions)two lists of membership paths, one per commitment and one per message leaf (null for one not in the tree), plus the root they are all under
getPublications(from_position, limit)a page of published messages from a position, which a scanning client reads to find its own
getMessagePath(position)the path for one published message
getRecoveryBinding(address)the binding that lets an owner recognise a stored message
getProgramIds()one hardcoded entry for the privacy circuit, the single id wallet check-health compares. Its implementation carries a TODO to read programs from state, so it is not a program inventory
getSystemProposals(), submitSystemApproval(..)the system upgrade queue and a committee approval
getSequencerStatus()whether the sequencer is still bootstrapping from the channel or online

A submission can be refused before it reaches the mempool:

ConditionAnswer
the decoded size its base64 implies exceeds 1,835,008 (the largest block size any chain can set)-32602, message Invalid params, with payload of up to N bytes exceeds 1835008 in the error’s data, since it fails while the parameters decode
it is malformed or calls a sequencer-only programInvalidParams (-32602), the cause in the message
it would not fit in a block under this chain’s max_block_sizethe same
its fee fails the fee screenthe same
a signer’s nonce is below its account’s, or a signer fails authentication at the head or against a pending transactionthe same
a slot it claims is already pending, or a signer is at its pending limitthe same
a private transaction’s commitment, nullifier or recovery binding is already in the headthe same
the mempool is full-31900
a private fee reserve the head base fee has outgrown-31901: price it again and resubmit
the sequencer is not online yet-31902

It also answers reads at its head, so a client needing only current state can talk to one service: getAccount, getAccountView, getAccountBalance, getAccountsNonces, getBlock(block_id), getBlockRange(start, end), getLastBlockId, getTransaction(hash) (the transaction and its block id), and getTransactionReceipt(hash), plus checkHealth. The code marks all but checkHealth for removal once the wallet reads through the indexer. Blocks and transactions come back as base64 of their borsh bytes, not JSON, so reading them takes the Rust types.

The shape an account comes back in

An account is a nonce and a map from program account id to that program’s actor state. The native balance is one of those entries, under the native token program, not a field of its own:

{
  "nonce": 0,
  "data": { "actor_states": { "<program account id>": "<base64 bytes>" } }
}

actor_states is keyed by program, so a client reads only the entries it cares about. The bytes are whatever that program writes, and decoding them is the client’s job: the indexer does not know a program’s state layout. wallet account get --raw --scope all --account-id <account id> prints the same entries, flattened to actor_states and nonce with hex bytes.

Prefer getAccountSummary or getAccountView for list views: a full read of an account with large actor states can exceed the response limit.

The two things the indexer cannot do

It cannot read private accounts. The chain holds only a commitment and an encrypted note, and the server does not have the keys, so no RPC method returns a private account’s state. The only path is a client holding them: the wallet library (Building on the wallet library) and its sync-private scan.

It cannot tell you about a refused transaction, because there is nothing to query. A private transaction whose public part fails at settlement is refused when the failure is not chargeable or nothing pays for it; with a fee fallback in its proof, or a fee a public signer declares, it is included as a paid revert (Reading the chain). A client polling for one it submitted must treat “not found” as a possible terminal state, not “not yet”: nothing records the refusal, and a transaction still waiting in the mempool looks the same, so the client decides how long to wait before treating it as refused. The wallet’s poller gives up after a fixed number of timed polls, not blocks (It lags the sequencer).

It lags the sequencer

For submission and immediate confirmation use the wallet library’s poller: poll_tx(tx_hash) returns the transaction and the block it landed in, and poll_block_range walks a range (lez/wallet/src/poller.rs). Its patience is the wallet config’s (up to seq_tx_poll_max_blocks polls seq_poll_timeout apart), and running out ends in Transaction not found in preconfigured amount of blocks, which is not a verdict.

The division that works: submit and confirm through the wallet library, display and search through the indexer.

The explorer

lez/explorer_service is a Leptos front end over the same RPC surface, run as Running a node shows, and a worked example of the read path (it calls get_last_finalized_block_id, among others). It is not a stable integration surface and may change or go away.