The rule for a failed read
A read that fails throws. It never answersfalse, 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
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
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
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
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
null. Every read is at one block: options.block, or the uncached tip.
The client decides in this order:
- It reads the live adapters (
readLiveDelegationAdapters). - 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))istrueandadmittedSafeSingletons(masterCopy())istrueon the adapter. - Else, if the
erc20_allowrow is live and the account has no code or an EIP-7702 pointer, it returns the ERC20Allow adapter. - Else it returns
null.
delegationAdapters.safe and delegationAdapters.erc20_allow, or use delegationAdapterOfKind.
readDslCommitment
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
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
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.
confirmedBlock of the commit, and then call recover. Treat null as “unknown”, not as “behind”.
Account discovery
discoverAccounts
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 withBlockReadOptions follows this rule (readAtBlock):
- The SDK reads at
block. - If the answer is a JSON-RPC error with a numeric code, the node is behind. The SDK waits and asks again.
- If the answer is empty (a viem zero-data error, or an empty value) and
targetHasCodeistrue, the node is behind. The SDK waits and asks again. - A revert that carries data, an HTTP error, a malformed answer, and any other failure end the read at once with that error.
- The first wait is 1 second. Each later wait doubles, up to 3 seconds.
- No attempt starts at or after
deadlineor aftersignalaborts. Then the read throws the last failure, or anError("... passed its deadline"), or the abort reason.
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
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
read under the retry rule. isEmptyAnswer tells which answers are empty; they count as “behind” only when targetHasCode is true.
settleWithinBounds
{ 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
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
readLiveDelegationAdapters.
classifyErc20AllowAccount (function)
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
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
readAccountAdapter, with the same order of checks.