Overview
TypeScript SDK for confidential smart contracts — shield, transfer, and unshield tokens with Fully Homomorphic Encryption.
Last updated
# React app
pnpm add @zama-fhe/react-sdk @zama-fhe/sdk @tanstack/react-query
# Vanilla TypeScript / Node.js
pnpm add @zama-fhe/sdk# React app
npm install @zama-fhe/react-sdk @zama-fhe/sdk @tanstack/react-query
# Vanilla TypeScript / Node.js
npm install @zama-fhe/sdk# React app
yarn add @zama-fhe/react-sdk @zama-fhe/sdk @tanstack/react-query
# Vanilla TypeScript / Node.js
yarn add @zama-fhe/sdkimport { createPublicClient, createWalletClient, custom, http } from "viem";
import { sepolia } from "viem/chains";
import { createConfig } from "@zama-fhe/sdk/viem";
import { ZamaSDK } from "@zama-fhe/sdk";
import { web } from "@zama-fhe/sdk/web";
import { sepolia as sepoliaFhe, type FheChain } from "@zama-fhe/sdk/chains";
const publicClient = createPublicClient({ chain: sepolia, transport: http() });
const walletClient = createWalletClient({ chain: sepolia, transport: custom(window.ethereum!) });
const mySepolia = {
...sepoliaFhe,
relayerUrl: "https://your-app.com/api/relayer/11155111",
} as const satisfies FheChain;
const config = createConfig({
chains: [mySepolia],
publicClient,
walletClient,
relayers: { [mySepolia.id]: web() },
});
const sdk = new ZamaSDK(config);
const wrappedToken = sdk.createWrappedToken("0xYourWrappedToken");
await wrappedToken.shield(1000n); // deposit public tokens
const [address] = await walletClient.getAddresses();
const balance = await wrappedToken.balanceOf(address); // decrypt your balance
await wrappedToken.confidentialTransfer("0xRecipient", 500n); // private send
await wrappedToken.unshield(500n); // withdraw back to public