Skip to content

@mistcash/react

The React package provides the useMist hook — a single hook that manages the full lifecycle of privacy transactions including key input, asset fetching, proof generation, and withdrawal.

Terminal window
pnpm add @mistcash/react @mistcash/sdk @mistcash/config

Peer dependencies: react@^19.1.0

The React package also depends on @starknet-react/core and @starknet-react/chains for Starknet wallet integration.

function useMist(
provider: ProviderInterface | undefined,
sendTx: (calls: Call[]) => void
): UseMistResult;

Parameters:

ParameterTypeDescription
providerProviderInterface | undefinedStarknet provider instance from your wallet connection
sendTx(calls: Call[]) => voidFunction to send transactions (from @starknet-react/core)

The hook returns an object with the following properties:

PropertyTypeDescription
chamberAddressstringThe Chamber contract address
contractChamberTypedContractTyped contract instance
txLeavesbigint[]Current Merkle tree leaves
PropertyTypeDescription
loadingStatus"FINDING_TX" | "READY"Current loading state
loadingMessagestringHuman-readable loading message
PropertyTypeDescription
valKeystringCurrent claiming key input
setKey(val: string) => voidSet the claiming key
valTostringCurrent recipient address input
setTo(val: string) => voidSet the recipient address
PropertyTypeDescription
assetAsset | undefinedFound asset details
setAsset(asset: Asset | undefined) => voidSet asset manually
setAssetAddr(addr: string) => voidSet asset token address
setAssetAmt(amount: bigint) => voidSet asset amount
PropertyTypeDescription
send(calls?: Call[]) => voidSend a transaction
fetchAsset() => Promise<Asset>Fetch asset for current key/to
updateTxLeaves() => Promise<bigint[]>Refresh Merkle tree leaves
handleWithdraw(asset: Asset, newTxAmount?: string) => Promise<void>Execute withdrawal with ZK proof
PropertyTypeDescription
isPendingbooleanTransaction in progress
errorstring | nullError message
txErrorError | nullTransaction error object
PropertyTypeDescription
valSnHTostringSeek-and-hide recipient
setSnHTo(val: string) => voidSet seek-and-hide recipient
valSnHKeystringSeek-and-hide key
setSnHKey(val: string) => voidSet seek-and-hide key
valSnHAmtstringSeek-and-hide amount
setSnHAmt(val: string) => voidSet seek-and-hide amount
  1. Set up your Starknet provider

    import { useAccount, useProvider } from "@starknet-react/core";
    function App() {
    const { provider } = useProvider();
    const { account } = useAccount();
    const sendTx = (calls) => {
    account?.execute(calls);
    };
    return <PrivacyWallet provider={provider} sendTx={sendTx} />;
    }
  2. Use the useMist hook

    import { useMist } from "@mistcash/react";
    function PrivacyWallet({ provider, sendTx }) {
    const mist = useMist(provider, sendTx);
    return (
    <div>
    <h2>MIST.cash Privacy Wallet</h2>
    <p>Status: {mist.loadingMessage}</p>
    <label>
    Claiming Key
    <input
    value={mist.valKey}
    onChange={(e) => mist.setKey(e.target.value)}
    />
    </label>
    <label>
    Recipient Address
    <input
    value={mist.valTo}
    onChange={(e) => mist.setTo(e.target.value)}
    />
    </label>
    <button
    onClick={() => mist.fetchAsset()}
    disabled={!mist.valKey || !mist.valTo}
    >
    Find Transaction
    </button>
    {mist.asset && (
    <div>
    <p>Found: {mist.asset.amount.toString()} of {mist.asset.addr}</p>
    <button
    onClick={() => mist.handleWithdraw(mist.asset!)}
    disabled={mist.isPending}
    >
    {mist.isPending ? "Generating proof..." : "Withdraw"}
    </button>
    </div>
    )}
    {mist.error && <p style={{ color: "red" }}>{mist.error}</p>}
    </div>
    );
    }

When handleWithdraw is called, the hook performs the following steps internally:

  1. Fetches the current Merkle tree leaves from the contract
  2. Finds the transaction index in the tree
  3. Computes the Merkle root and proof path
  4. Constructs the witness object
  5. Generates a Groth16 zero-knowledge proof (WASM)
  6. Formats the proof as Starknet calldata (Garaga)
  7. Submits the withdrawal transaction via sendTx