Skip to main content
This page covers the core SDK lifecycle:
  1. Create config (createCofheConfig)
  2. Create client (createCofheClient)
  3. Connect (client.connect)
  4. Manage connection (change account / disconnect)

1. Create config

Import createCofheConfig from the entrypoint that matches your runtime:
  • Browser apps: @cofhe/sdk/web
  • Node.js scripts/backends: @cofhe/sdk/node
The only required field is supportedChains.

2. Create the client

3. Connect

The SDK connects to CoFHE using viem clients:
  • PublicClient: read-only chain access
  • WalletClient: signing + sending transactions
The wallet client must carry an account. connect reads the connected address from walletClient.account, and falls back to eth_accounts on the transport. A wallet client created with http() and no account has neither, so connect throws PublicWalletGetAddressesFailed and the client stays disconnected. In the browser, take the account from the injected wallet. In Node.js, build it from a private key.

Using adapters

If you use Ethers, @cofhe/sdk/adapters converts an Ethers provider and signer into viem-shaped clients, and derives the account from the signer. wagmi already gives you viem clients, so pass them to connect directly. The wallet client from useWalletClient carries the connected account.

4. Managing connections

Reconnect behavior

Calling connect again with the same clients is a no-op. Calling it with new clients replaces the connection state.

Changing connected account

To switch the client’s connected account, call cofheClient.connect() with a wallet client that carries the new account.

Disconnecting

To manually disconnect, call cofheClient.disconnect(). This clears the in-memory connection state (clients/account/chainId) and marks the client as disconnected. It does not delete persisted ACPs or stored FHE keys.