React SDK
Overview of @mpckit/react. Provider, query hooks, and mutation hooks over MPCKit.
@mpckit/react wraps the imperative MPCKit class in a Provider
plus a set of TanStack-Query-shaped hooks. The Provider also handles
the boilerplate of constructing a Web Worker crypto engine when
useWorker is set, so DKG and sign ceremonies don't block the main
thread.
Peer deps: react@>=18, @tanstack/react-query@>=5.
You own the QueryClient
The SDK doesn't ship its own QueryClientProvider. Wrap
<MPCKitProvider/> in your app's <QueryClientProvider client={...}/>
so every hook participates in your app's cache, devtools, and
invalidation.
Install
bun add @mpckit/react @mpckit/sdk @tanstack/react-querypnpm add @mpckit/react @mpckit/sdk @tanstack/react-querynpm install @mpckit/react @mpckit/sdk @tanstack/react-queryAt a glance
"use client";
import {
MPCKitProvider,
useBalance,
useOnboard,
Curve,
} from "@mpckit/react";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
const queryClient = new QueryClient();
export function Root({ children }: { children: React.ReactNode }) {
return (
<QueryClientProvider client={queryClient}>
<MPCKitProvider
options={{
baseUrl: "https://api.mpckit.xyz",
apiKey: process.env.NEXT_PUBLIC_MPCKIT_API_KEY!,
network: "testnet",
}}
>
{children}
</MPCKitProvider>
</QueryClientProvider>
);
}
function CreditsBadge() {
const { data } = useBalance();
return <span>{data?.creditsUsd ?? "…"}</span>;
}Where to go next
Provider
MPCKitProvider, options, and the worker factory.
Query hooks
useBalance, useDWallet, useDWallets, and friends.
Mutation hooks
useOnboard, useSign, useDeclareDeposit.
Imperative escape hatches
useMPCKit and useEdenClient.
Query keys
Invalidate manually with mpcKitQueryKeys.
Re-exports
Constants, errors, and types from the core SDK.