- Create config (
createCofheConfig) - Create client (
createCofheClient) - Connect (
client.connect) - Manage connection (change account / disconnect)
1. Create config
ImportcreateCofheConfig from the entrypoint that matches your runtime:
- Browser apps:
@cofhe/sdk/web - Node.js scripts/backends:
@cofhe/sdk/node
supportedChains.
2. Create the client
3. Connect
The SDK connects to CoFHE using viem clients:PublicClient: read-only chain accessWalletClient: signing + sending transactions
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
Callingconnect 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, callcofheClient.connect() with a wallet client that carries the new account.
Disconnecting
To manually disconnect, callcofheClient.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.