Next.js SSR
How to use the SDK with Next.js and server-side rendering frameworks.
Steps
1. Understand the constraint
2. Mark SDK components with "use client"
"use client""use client";
import { useConfidentialBalance } from "@zama-fhe/react-sdk";
import { useAccount } from "wagmi";
export function TokenBalance({ tokenAddress }: { tokenAddress: string }) {
const { address } = useAccount();
const { data: balance, isLoading } = useConfidentialBalance({
address: tokenAddress,
account: address,
});
if (isLoading) return <span>Loading...</span>;
return <span>{balance?.toString()}</span>;
}3. Place ZamaProvider inside a client component
ZamaProvider inside a client component4. Use the provider in your layout
5. Avoid creating SDK objects in server components
6. Example: page with a confidential balance
Next steps
Last updated