For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to page URLs.
Skip to content

Configuration

How to configure the SDK in TypeScript, Go, and Rust with chains, relayers, provider, signer, and storage.

The SDK uses createConfig to wire together chains, relayers, a provider, an optional signer, and storage into a single configuration object. This guide walks through each piece. In Go and Rust, the same settings configure an SDK context in the daemon.

Steps

1. Pick your chains

Import pre-configured chain objects from @zama-fhe/sdk/chains. Each chain includes contract addresses, relayer URLs, and chain IDs.

import { sepolia, mainnet, hoodi } from "@zama-fhe/sdk/chains";

Select a preset by chain ID and supply its RPC URL:

config := zama.NewSDKConfig(11155111, rpcURL) // Sepolia preset

Select a preset by chain ID and supply its RPC URL:

let config = SdkConfig::new(11_155_111, rpc_url); // Sepolia preset
Chain
Chain ID
Description

mainnet

1

Ethereum Mainnet

polygon

137

Polygon Mainnet

sepolia

11155111

Sepolia Testnet

polygonAmoy

80002

Polygon Amoy Testnet

hoodi

560048

Hoodi Testnet

zenithTrexTestnet

936486

T-Rex Zenith Testnet

bscTestnet

97

BNB Smart Chain Testnet

hardhat

31337

Local Hardhat node

anvil is also exported as an alias for hardhat (both target chain ID 31337), for Foundry users.

The shared Zama testnet relayer needs no API key: presets like sepolia and polygonAmoy work as-is, so leave auth unset. Only the Zama-hosted mainnet relayer (used by mainnet and polygon) requires a key; see Authentication.

2. Pick a relayer

Relayers tell the SDK how to run FHE operations on each chain.

Relayer
Environment
Description

web()

Browser

Runs FHE via bundled WASM in the browser

node()

Node.js

Same FHE runtime, server-side

cleartext()

Local dev

No FHE infrastructure — cleartext operations

Chain-specific data (relayerUrl, network, executorAddress, etc.) comes from the chain preset, so a bare call is all most apps need. Each factory also accepts an optional options object forwarded to @fhevm/sdk for per-client tuning (e.g. batchRpcCalls, fheEncryptionKey, moduleVersions, timeout) — see the web() / node() / cleartext() reference for the full option list and defaults.

web() additionally runs encryption in a dedicated Web Worker by default, so encryptValue()/encryptValues() calls don't block the main thread. Tune or opt out of this with offloadEncrypt, offloadWorker, and offloadTimeouts — see web()'s encryption offload options for the full behavior and defaults. If your app sets a Content Security Policy, it needs worker-src 'self' blob: for the offload worker to start.

Omit Relayers to use the node relayer for every configured chain. web() is browser-only.

Leave relayers as None to use the node relayer for every configured chain. web() is browser-only.

The relayers map is keyed by chain id, one entry per chain in chains. A chain with no entry fails createConfig with a ConfigurationError. An entry whose chain is not in chains is unused and only warns through the configured logger, so a static relayer catalog can serve an environment-filtered chain list.

If you need to override a chain field (e.g. proxy relayer requests through your backend), spread the preset in the chains array:

Fields you omit keep their preset values. Set Auth on the chain for relayer authentication.

Fields you omit keep their preset values. Set auth on the chain for relayer authentication.

3. Set up chain access

The SDK separates read access (provider) from wallet authority (signer). The provider handles contract reads and receipt polling. The signer handles signing and write transactions. Both are created automatically by createConfig — you pass your Web3 library's native objects.

The daemon reads the chain through the configured RPC URL. Your application keeps the wallet and passes a signer when creating the SDK context:

The daemon reads the chain through the configured RPC URL. Your application keeps the wallet and passes a signer when building the SDK context:

For full type information, see the ViemProvider / ViemSigner and EthersProvider / EthersSigner reference pages. You can also implement GenericProvider and GenericSigner for a custom integration. For Go and Rust transaction writes and custom wallets, see Attach a wallet.

4. Create the config

createConfig takes your chains, relayers, and signer adapter and returns a config object.

When the built-in adapters don't fit your setup — for example, a server-side relayer that implements GenericSigner directly — use the generic createConfig from @zama-fhe/sdk:

See GenericSigner and GenericProvider for the interfaces your adapter must implement.

MV3 Chrome extensions can use chromeSessionStorage as permitStorage so permits survive service worker restarts:

Your manifest.json must include the "storage" permission. See the Web Extensions guide for manifest configuration, multi-context sharing, and browser close behavior.

Connect to the daemon socket, then create an SDK context from the config. Close the context when done; the first context in a daemon process fixes its runtime settings.

Connect to the daemon socket, then build an SDK context from the config. Close the context when done; the first context in a daemon process fixes its runtime settings.

Browser apps should proxy relayer requests through a backend to keep the API key secret. See the Authentication guide for the full setup.

5. (Optional) Configure TTLs, credential cleanup, and event listener

You can tune how long the transport key pair and permits remain valid, choose whether a wallet account change clears the previous account's credentials, and subscribe to lifecycle events for debugging:

See Observe events for the other event handlers.

Diagnostics implements EventHandler; see Observe events.

By default, a wallet account change, lock, or disconnect clears the previous account's permits, transport key pair, and decrypt cache. Set clearCredentialsOnWalletChange: false to keep them: both are keyed per signer address and expire on their own, so a user switching between accounts does not sign a new permit each time. With the option off, call sdk.permits.clear() in your sign-out flow before disconnecting the wallet; it needs a connected wallet account. The Go and Rust clients always clear on UpdateAccount / update_account; the option is not exposed to them yet. See the Permit Model.

When done with the SDK, call sdk.terminate() to unsubscribe wallet listeners and release the SDK's resources.

6. (Optional) Choose a storage backend

The transport key pair is cached so users don't get a wallet popup on every decrypt. By default, createConfig picks the right storage for your environment. Override with the storage field if needed:

Storage
When to use

indexedDBStorage

Browser apps — persists across reloads and sessions

memoryStorage

Tests, scripts, throwaway sessions

asyncLocalStorage

Node.js servers — isolates transport key pair per request

Daemon SQLite needs a storage volume on the daemon; see Deploy in production.

Daemon SQLite needs a storage volume on the daemon; see Deploy in production.

For full storage options see the GenericStorage reference. To keep Go or Rust credentials in your own database, see Store credentials.

7. (Optional) Supply a logger

Available in the Core SDK and React SDK.

The SDK is silent by default — it emits no console output of its own. Operation failures always surface through the rejected promise or typed error, never as a stray console.error. To observe internal diagnostics, pass a logger to createConfig:

The logger is a minimal four-level interface — error, warn, info, debug — that console and common logging libraries satisfy directly, so no adapter is needed. The SDK never bundles a logging library or imposes a format; level filtering is left to your logger. Levels follow these conventions:

Level
What the SDK emits

error

Unexpected internal failures only — never failures already surfaced via a rejection

warn

Recoverable or degraded conditions (a fallback path, a retry, a swallowed best-effort write)

info

Reserved for coarse lifecycle milestones; not currently emitted

debug

Verbose diagnostics — relayer request timing, orchestration progress

The logger is configured once here and flows SDK-wide — including into relayer request tracing, the credential store, and the decrypt cache. There is deliberately no per-relayer logger option; createConfig({ logger }) is the single source of truth.

8. (Optional) Tune FHE runtime performance and behavior

The runtime field configures the underlying @fhevm/sdk WASM runtime — how WASM assets load, threading, and module versions. It is process-global: it applies once per process, not per chain or per relayer.

Leaving runtime unset is a valid default: the SDK tries to run multi-threaded automatically, and falls back to single-threaded on its own when the environment doesn't support it (see numberOfThreads/singleThread below).

The runtime runs in the daemon. Restart the daemon to change these settings.

The runtime runs in the daemon. Restart the daemon to change these settings.

Every field is optional:

Field
Default
Effect

numberOfThreads

requested: navigator.hardwareConcurrency

Number of Web Workers to parallelize FHE encryption/decryption across. This is the requested count — the effective count degrades to single-threaded (see singleThread below) where navigator is unavailable (Node < 21, some edge runtimes), or where SharedArrayBuffer/a spawnable worker isn't.

singleThread

false

true forces a single thread — no SharedArrayBuffer required. The SDK also auto-upgrades to this at runtime whenever multi-threading was requested but can't actually run (no cross-origin isolation, no way to spawn a worker for the chosen wasmAssetLoadMode) — silently, with a console warning, never an error.

wasmAssetLoadMode

"auto"

How the TFHE/KMS WASM assets are fetched and instantiated (modes below).

moduleVersions

"auto"

Pin the TFHE/KMS WASM module versions instead of auto-resolving them from the chain's on-chain protocol version. checkCompatibility — checked only when a concrete version is pinned — defaults to "throw"; also accepts "warn" or "off".

locateFile

none

Remap where the WASM assets are served from — set this when self-hosting them.

auth

none

Process-wide fallback relayer authentication, applied to any chain that doesn't set its own auth. See Authentication for the auth methods.

wasmAssetLoadMode controls how the FHE WASM assets are fetched and instantiated:

Mode
Behavior

auto (default)

Pick the best mode available in the current environment.

embedded-base64

Use the WASM inlined as base64 — no separate network fetch. Useful under strict CSP or offline.

verified-blob

Fetch the WASM, verify its integrity, then instantiate from the verified blob.

precheck-direct-url

Load directly from the asset URL after a precheck request.

trusted-direct-url

Load directly from the asset URL with no precheck (fastest, least defensive).

runtime.logger is not one of these — it's managed by the SDK. Pass your logger via createConfig's top-level logger instead (step 7 above).

9. (Optional) Share one transport key pair across signers (B2B2C / WaaS)

By default, every signer gets its own transport key pair. Wallet-as-a-Service operators managing many end-user wallets from one operator-controlled key store can opt into sharing a single key pair across signers with transportKeyPairScope:

Permits stay per-signer regardless of scope. See Security Model for the tradeoff this makes, and Permit Model for how revocation splits into a signer-level tier (revokePermits/clear) and an operator-level one (sdk.permits.revokeTransportKeyPair()).

10. (Optional) Wrap the transport key pair at rest (headless environments)

By default the SDK stores the transport private key in plaintext and delegates at-rest security to your storage backend. transportKeyPairDerivationSecret encrypts the key before every write instead. It exists for headless environments that have no secure backend to delegate to. Find your environment:

Your environment
What to do

Browser dApp

Nothing. IndexedDB behind same-origin isolation and OS disk encryption is the intended default. The constructor rejects this option.

React Native / mobile

Use a platform keychain (iOS Keychain, Android Keystore) as the storage backend. React Native defines window, so the constructor rejects this option too.

Backend with a KMS, Vault, or encrypted storage

Nothing. Your storage is already secure; wrapping on top adds key management without adding security.

Headless with plain storage (CLI tool, agent, bare-metal box)

Pass transportKeyPairDerivationSecret, plus a persistent storage.

For the last row, two things must hold:

  1. The secret arrives out of band: from the process environment, a secrets manager, or a KMS-unwrapped blob. Never store it next to the data it protects.

  2. Storage is persistent. The headless default is in-memory, and a wrapped key that never reaches disk protects nothing.

Pass process.env.ZAMA_DERIVATION_SECRET straight through, without asserting it with ! first. If the value is undefined (an unset env var), the constructor throws ConfigurationError instead of silently downgrading to plaintext.

An unset variable produces an empty secret, which the SDK rejects. Use zama.BytesDerivationSecret for byte input.

Use DerivationSecret::bytes for byte input.

Keep the same secret and storage when you recreate a Go or Rust SDK context or restart the daemon.

The SDK never persists or exposes this value. See Security Model for the mechanism, the entropy requirement (32 random bytes, or a 64+ character string), the anti-patterns to avoid, and rotation.

Shared relayer options

Available in the Core SDK and React SDK.

When multiple chains use the same relayer, create it once and reference that single instance from each chain:

Chains that reference the same relayer object — the result of a single web() call — share one FHE backend instance, reducing memory usage.

Next steps

Last updated