Recipe · Setup · Custom RPC

Use your own RPC behind viem

The SDK is RPC-agnostic: it takes a viem PublicClient + WalletClient, both of which carry their own transports. Switch providers by switching transports, no SDK-side change.

Alchemy / Infura / your own#

viem's http() transport accepts any URL. Server-side it can read from process.env; in the browser the URL ships in the bundle, so use a proxy if you want the API key to stay private.

lib/client.ts
ts
import { createPublicClient, http } from "viem";
import { sepolia } from "viem/chains";

const publicClient = createPublicClient({
  chain: sepolia,
  transport: http(`https://eth-sepolia.g.alchemy.com/v2/${ALCHEMY_KEY}`),
});

// Hand off to any SDK client. No SDK-side RPC config to update.
import { createConfidentialVestingFactoryClient } from "@tokenops/sdk/fhe-vesting";

const factory = createConfidentialVestingFactoryClient({
  publicClient,
  walletClient,
});

Override at the wagmi config level#

If you use wagmi (the React route), set the chain's transport in the config and the SDK picks it up automatically through usePublicClient.

src/wagmi.ts
ts
// Override the default RPC at the chain level for wagmi.
import { createConfig, http } from "wagmi";
import { sepolia } from "viem/chains";

export const wagmiConfig = createConfig({
  chains: [sepolia],
  transports: {
    [sepolia.id]: http("https://your-custom-sepolia-rpc.example.com"),
  },
});

Non-Sepolia, non-mainnet chains#

FHEVM products only ship on Sepolia + mainnet today (see DEPLOYED_ADDRESSES). You can use any RPC for THOSE chains, but adding a third FHEVM chain requires the contracts to deploy there first, the SDK won't let you call into an address it doesn't have registered.

See also