Skip to main content
After you read this page, you can read every chain fact that a flow needs, pin a read to the block of an earlier write, and know which reads can fail.

The rule for a failed read

A read that fails throws. It never answers false, null or 0 in place of an answer. For example, isWalletDeployed rejects when the node fails, and it does not answer false. Catch the error and retry, or show that the state is unknown. Two client methods are exceptions. readEngineSyncedHeight answers null on any failure. readWalletAtomicBatchSupport answers false on any failure. Each entry says so.

Engine and account reads

readEngineEncKey

Reads AnafiRegistry.engineEncKey() at the latest block and returns the 32 raw bytes of the X25519 public key of the engine. The SDK seals each rule document and each confidential request to this key.

predictSafe

Returns the address of the deterministic 1-of-1 Safe of the owner eoa. The address follows from the configured Safe framework addresses and the live creation code of the proxy factory. The Safe does not need to exist. provisionPredictedSafe deploys the Safe at this address. The prediction uses predictSafeAddress from the low-level helpers: owners [eoa], threshold 1, a setup that moves the Safe to SafeL2, and the salt nonce keccak256(eoa).

isWalletDeployed

Answers true when the address has code. Code 0x, null and undefined count as no code. With options, the read is pinned to options.block under the retry rule.

readLiveDelegationAdapters

Reads AnafiRegistry.delegationAdapters() and returns each row of your delegationAdapters config that the registry lists. A row that the registry does not list is absent from the result. An adapter that the registry lists but your config does not name is not in the result either.

readAccountAdapter

Returns the live configured adapter that can serve the account, or null. Every read is at one block: options.block, or the uncached tip. The client decides in this order:
  1. It reads the live adapters (readLiveDelegationAdapters).
  2. If the Safe row is live and the account is a Safe that the Safe adapter admits, it returns the Safe adapter. “Admits” means that admittedSafeProxyCodehashes(keccak256(code)) is true and admittedSafeSingletons(masterCopy()) is true on the adapter.
  3. Else, if the erc20_allow row is live and the account has no code or an EIP-7702 pointer, it returns the ERC20Allow adapter.
  4. Else it returns null.
The answer is a structural fact. It does not say that the account granted a permission or committed a document. A plain address with no code always gets the ERC20Allow adapter when that leg is live. To know the kind, compare the answer with delegationAdapters.safe and delegationAdapters.erc20_allow, or use delegationAdapterOfKind.

readDslCommitment

Reads AnafiDslRegistry.commitments(aa) at the latest block. Returns null when the version is 0 (nothing committed). Pass the answer as the parent of your next stage.

readDslCommitmentAtBlock

The same read at a block. With a bare bigint, it reads once at that block. With BlockReadOptions, it reads under the retry rule. Use it after a commit, with the confirmedBlock of the commit, so that a node behind that block cannot answer with the old document.

readEngineSyncedHeight

Returns the last block that the engine has processed, or null. It never throws. It returns null in each of these cases:
  • No answer arrives, or the request times out.
  • The answer has a status that is not 2xx.
  • The body is not JSON, or it has no height.
  • The height is not a whole number of 0 or more.
  • The engine reports no height yet.
Use it to wait until the engine has processed a block before a read-back. After a commit, the engine reads the commit only when it has processed the block of the commit. Poll until the height is at or above the confirmedBlock of the commit, and then call recover. Treat null as “unknown”, not as “behind”.

Account discovery

discoverAccounts

Calls GET /api/accounts/discover?eoa=<eoa> and returns the accounts that this owner key might use. Discovery is advisory. A suggestion authorizes nothing. Each action on a suggested account needs the signature of that account. The client reads every row. It drops a row with an unknown kind, an unknown source, a bad address, or a field of the wrong type. It reads at most 64 rows. When it drops or cuts a row, it sets completeness to UNRECOGNIZED_COMPLETENESS, whatever the API said.
Never tell the user that an account does not exist when completeness is not every_source_consulted. The package also exports the function that the method calls:

Block-pinned reads

A load-balanced RPC can send two calls to two nodes. A read right after a write can reach a node that has not seen the write. A read pinned at the block of the write cannot take the old state as the answer. A node below the block answers with a JSON-RPC error, and the SDK asks again until a deadline.

BlockReadOptions

The retry rule

A read with BlockReadOptions follows this rule (readAtBlock):
  1. The SDK reads at block.
  2. If the answer is a JSON-RPC error with a numeric code, the node is behind. The SDK waits and asks again.
  3. If the answer is empty (a viem zero-data error, or an empty value) and targetHasCode is true, the node is behind. The SDK waits and asks again.
  4. A revert that carries data, an HTTP error, a malformed answer, and any other failure end the read at once with that error.
  5. The first wait is 1 second. Each later wait doubles, up to 3 seconds.
  6. No attempt starts at or after deadline or after signal aborts. Then the read throws the last failure, or an Error("... passed its deadline"), or the abort reason.
Without BlockReadOptions, a read asks once: at the latest block, or at the bare bigint block that you give. The client uses a deadline of 20 seconds for its own reads after its own writes.

resolveReadBlock

Chooses the block for a read after a write at floor. It reads the tip once, uncached. It returns floor when the node that answered is below floor, and the tip in all other cases. It does not loop: the reads pinned at floor do the wait. With bounds, the tip read stops at the deadline or at the abort, and the method throws.

readAtBlock

Runs your read under the retry rule. isEmptyAnswer tells which answers are empty; they count as “behind” only when targetHasCode is true.

settleWithinBounds

Answers { inTime: true, value } when work resolves before the deadline and before the abort. Answers { inTime: false } as soon as the deadline or the abort comes first. A rejection before them rejects. The SDK ignores what work does later.

Adapter and account classification helpers

These functions take a public client and do what the client methods do. Use them when you have no client.

delegationAdapterOfKind

Returns adapters.safe for safe_module and adapters.erc20_allow for erc20_allow.

isEmptyCode and isEip7702DelegationCode

isEmptyCode answers true for 0x, null and undefined. isEip7702DelegationCode answers true only for code of exactly 23 bytes that starts with 0xef0100: an EIP-7702 delegation pointer.

Erc20AllowAccountClass and isServedErc20AllowAccountClass

readLiveConfiguredAdapters

The function behind readLiveDelegationAdapters.

classifyErc20AllowAccount (function)

Answers leg_not_live with no read when configured.erc20_allow is absent, and after the registry read when the registry does not list it. Else it reads the code of account at at and classifies it. An empty code is a valid answer here, so the code read never retries on an empty answer. The client method of the same name is on ERC20Allow.

accountMatchesSafeAdapter

Answers true when the account is a Safe that adapter admits: its runtime code hash is in admittedSafeProxyCodehashes, and its masterCopy() is in admittedSafeSingletons. Empty code answers false, unless at sets targetHasCode; then the empty code counts as a node behind the block. See the Safe adapter.

readClassifiedAccountAdapter

The function behind readAccountAdapter, with the same order of checks.