DocumentationReact hooks
DocsSDK reference

The React interface.

Fund notes, stream inference, and withdraw through hooks that share one purse client.

On this page

usePurse

Watch private state and coordinate the deposit flow. Hooks imported from @openzk.app/purse/react share the module’s client instance.

Read purse state
TSX
import { usePurse } from "@openzk.app/purse/react";

const { snapshot, journal, quote, depositStatus,
  requestQuote, startDeposit, errorMessage, reset } = usePurse();
usePurse interface
MemberPurpose
snapshotBalance in gwei, note status, current root, and note fingerprint.
journalClient-side deposit, burn, and withdrawal entries.
requestQuote(usd)Returns a DepositQuote, or null if quoting fails.
startDeposit(quote, undefined, address)Prepares and submits a deposit through the registered provider.
reset()Clears the deposit UI state; it does not delete the note.

Deposit phases: idle → quoting → awaiting_wallet_approval → awaiting_confirmation → journaling_note → ready. Errors use failed.

useBurn

Generate a payment proof, acquire a limited inference lease, stream a response, and settle usage. The model’s tierUsd sets the requested session spending limit.

Inference.tsx
TSX
import { useBurn } from "@openzk.app/purse/react";

export function Inference() {
  const { burn, streamingText, status, errorMessage } = useBurn();
  const busy = !["idle", "settled", "failed"].includes(status);

  return (
    <div>
      <button disabled={busy} onClick={() => burn(
        "Explain zero-knowledge proofs in one paragraph.",
        "Use plain language."
      )}>
        Send a request
      </button>
      <pre aria-live="polite">{streamingText}</pre>
      <p role="status">{status}</p>
      {errorMessage && <p role="alert">{errorMessage}</p>}
    </div>
  );
}
useBurn interface
MemberPurpose
burn(prompt, systemPrompt?)Runs inference against the selected model.
selectedModel / setSelectedModelReads or changes the selected ModelOption.
modelsCurated models plus the supported live catalog.
streamingTextResponse text accumulated as tokens arrive.
receipts / currentReceiptLocally stored request receipts and the current result.
statusidle, proving, leasing, streaming, settling, settled, or failed.

useExit

Close the note through a mutual withdrawal. Pass a valid Ethereum destination; the hook reports proof, clearance, wallet, and broadcast phases.

Withdraw a note
TSX
import { useExit } from "@openzk.app/purse/react";

const { withdraw, status, withdrawalDetails,
  errorCode, errorMessage, reset } = useExit();

// Run from your withdrawal confirmation handler.
await withdraw(recipientAddress);

Withdrawal phases: idle → proving → requesting_clearance → awaiting_wallet_approval → broadcasting → withdrawn. Errors use failed.

useModelCatalog

Read the model list without starting an inference request. The hook starts with curated models, then merges supported entries from the live OpenRouter catalog. Cached live entries are reused for up to 24 hours.

Read available models
TSX
import { useModelCatalog } from "@openzk.app/purse/react";

const models = useModelCatalog();
// readonly ModelOption[]: id, name, provider,
// context, costClass, tierUsd, description

Handle errors

Each payment hook exposes errorCode, errorMessage, and reset. Render the readable message next to the failed action and use the status to control pending buttons.

The hooks catch operation failures and update their error state. Check that state rather than assuming a rejected promise will always reach your component.

Troubleshooting

Diagnose asset loading, wallet setup, protocol errors, and delayed settlement.

Documentation for the OpenZK browser toolkit. Report a documentation issue ↗