Skip to main content
After you read this page, you can create a client for polygon-amoy or polygon, give it the right addresses and tokens, and connect a wallet that the client can use.

createAnafiClient

createAnafiClient returns a client bound to one chain. It does no I/O. It checks one thing: network must be one of NETWORKS, and NETWORK_CHAIN_IDS[network] must equal chainId. If not, it throws an Error:
The client does not check the other fields at creation. A wrong address shows up later as a refusal or a failed read. Use the addresses on this page or on deployments.
Call the Anafi API from a server, a script, or your own same-origin proxy. The Anafi API hosts answer CORS (Access-Control-Allow-Origin) only for https://app.ana.fi today. A browser page on another origin cannot call the API directly. Chain reads and owner-sent transactions do not go through the API, and this limit does not affect them.

AnafiClientConfig

AnafiClientAddresses

safe is optional. Without it, predictSafe, provisionPredictedSafe, an arm of a Safe with no code, a commit that enables the adapter, and a call to executeSafeOwnerCalls with 2 or more calls throw Error("this deployment configures no Safe singleton, proxy factory or MultiSend"). All three networks use the same Safe v1.5.0 framework addresses.

DelegationAdapters

The client checks each adapter that you pass to a method against this table. A Safe method refuses an adapter that is not delegationAdapters.safe. An ERC20Allow method refuses an adapter that is not delegationAdapters.erc20_allow. Many methods also read AnafiRegistry.delegationAdapters() to check that the registry still lists the adapter (“live”).

The viem clients

AnafiPublicClient

A viem PublicClient from createPublicClient has every method. The table says which methods need the optional ones. A method that needs an absent optional method throws an Error that says so.

AnafiWalletClient

signTypedData gets no account field. Your wallet client must know the owner account. With viem, create the wallet client with account set:
  • For a browser wallet (EIP-1193), pass the owner address as account. viem sends each request to the wallet.
  • For a local private key, wrap the viem client. The SDK passes account as an address string. viem treats an address string as a JSON-RPC account and asks the RPC node to sign, and a public node cannot sign. The wrapper below drops that field, so viem signs with the local key.
A wallet client may throw OwnerRequestCancelledError when it sees the signal of a payment method abort before it asks the wallet. The payment methods then answer stopped_before_request. See payments.

Complete config for polygon-amoy

This script runs in Node.js with a local test key. All addresses come from the polygon-amoy deployment.
Use a test key only. Never put a key that holds real funds in a script or an environment variable.
This script sets no siweDomain, so a call of recover or requestNotificationEmailCode from it throws. Read sign-in limits before you use these two methods.

Complete config for polygon

This config uses a browser wallet. In a browser on your own origin, set backendUrl to your own same-origin proxy of the Anafi API, because of the CORS limit above. The chain reads and the owner-sent transactions go from the page to the chain directly.
On polygon, USDC is the native Circle contract and USDC.e is the older bridged one. They are two tokens, and a rule never mixes them. For the token table of every network, see networks.

Addresses per network

These are the deployed values when this page was written. The registry can list a new adapter later. Read readLiveDelegationAdapters() to see the live list, and see deployments.

Sign-in limits

The two sign-in (EIP-4361) flows, recover and the notification-email code request (requestNotificationEmailCode), are accepted only when the sign-in message names the domain of the Anafi dapp, app.ana.fi. The Anafi API refuses a sign-in for another domain with status 422. An integration on another domain cannot complete these two flows today.

Network and token vocabulary

Hex

NETWORK_CHAIN_IDS, Network, NETWORKS

The type names every network token that the SDK knows. Anafi has a deployment only on polygon, xlayer and polygon-amoy. The other tokens name no deployment of Anafi. See networks.

RoutingToken, ROUTING_TOKENS, TOKEN_DECIMALS

RoutingToken is the set of token symbols that the SDK can write in a rule document. The spelling is exact and case-sensitive: USDC.e is bridged USDC, USDT0 is the ASCII name of the USD₮0 contract, and ETH, WETH and xETH are three different assets. The type does not say which token a network has. Use erc20s and native for that.

Erc20Token

One row of the erc20s table: the symbol that a document names, and its contract.

OnChainDsl

The identity of the committed document of an account, as AnafiDslRegistry.commitments(aa) holds it. The registry pair for “nothing committed” (version 0, zero hash) is never an OnChainDsl. Each reader maps it to null. You pass an OnChainDsl as the parent of a stage.

OnChainDslAtBlock

A registry identity together with the block that it was read at. No client method returns it. Use it to keep a read of readDslCommitmentAtBlock together with its block.

AccountKind

See accounts.

Other token constants

AnafiClient

AnafiClient is the interface of the object that createAnafiClient returns. The overview lists every method with a link to its entry.