Quickstart
This guide shows the full payment flow using @fluppy/react hooks — from wallet connection to a confirmed ZK payment on Stellar Testnet.
@fluppy/react is complete as an SDK layer. These examples show how developers integrate the SDK. Full migration of the existing Fluppy app to these hooks is a separate next phase.Payment Flow
1Wrap with FluppyProvider
Place FluppyProvider near the root of your application. All Fluppy hooks must be inside this provider to access the shared SDK configuration.
import { FluppyProvider } from '@fluppy/react';
import type { FluppyReactConfig } from '@fluppy/react';
import { useMemo } from 'react';
// Memoize config to prevent unnecessary re-renders
const fluppyConfig: FluppyReactConfig = {
stellarConfig: {
contractId: process.env.NEXT_PUBLIC_CONTRACT_ID!,
rpcUrl: process.env.NEXT_PUBLIC_RPC_URL!,
networkPassphrase: process.env.NEXT_PUBLIC_NETWORK_PASSPHRASE!,
},
networkPassphrase: process.env.NEXT_PUBLIC_NETWORK_PASSPHRASE!,
// merkleOptions is optional — defaults to /api/merkle-proof
};
export default function RootLayout({
children,
}: {
children: ReactNode;
}) {
return (
<html lang="en">
<body>
<FluppyProvider config={fluppyConfig}>
{children}
</FluppyProvider>
</body>
</html>
);
}2Connect Freighter Wallet
useFluppyWallet manages Freighter connection state.connect() requests wallet access and returns the connected Stellar address. All calls are SSR-safe via dynamic import.
'use client';
import { useFluppyWallet } from '@fluppy/react';
export function WalletButton() {
const {
address,
isConnected,
isConnecting,
connectionStatus,
error,
connect,
} = useFluppyWallet();
if (isConnected && address) {
return (
<div>
<span>Connected: {address.slice(0, 6)}...{address.slice(-4)}</span>
</div>
);
}
return (
<button
onClick={connect}
disabled={isConnecting}
>
{isConnecting ? 'Connecting...' : 'Connect Freighter'}
</button>
);
}| Property | Type | Description |
|---|---|---|
| address | string | null | Connected wallet address, or null |
| isConnected | boolean | True when status is connected |
| isConnecting | boolean | True during requestAccess() |
| connectionStatus | WalletConnectionStatus | disconnected | connecting | connected | error |
| connect() | () => Promise<string> | Requests Freighter access, returns address |
| refresh() | () => Promise<void> | Re-checks Freighter without popup |
3Create or Unlock Credential
useFluppyCredential manages a ZK credential stored locally in IndexedDB, encrypted with AES-GCM + PBKDF2. The raw secret never leaves the browser and is never logged.
'use client';
import { useFluppyCredential } from '@fluppy/react';
export function CredentialSetup() {
const {
status,
exists,
isLoading,
error,
create,
unlock,
} = useFluppyCredential();
// Create a new credential
async function handleCreate(password: string) {
const { secret } = await create(password);
// ⚠ Show the secret to the user EXACTLY ONCE as a backup phrase.
// After this function returns, the secret cannot be recovered without the password.
displayBackupPhrase(secret); // your UI responsibility
}
// Unlock an existing credential
async function handleUnlock(password: string): Promise<string> {
// Returns the raw secret — pass it to useFluppyPayment.pay()
// Do NOT log the secret. Do NOT store it in React state.
return await unlock(password);
}
// Render based on status
if (status === 'unknown') return <p>Checking credential...</p>;
if (status === 'not_found') {
return <button onClick={() => handleCreate('user-password')}>Create credential</button>;
}
return <p>Credential ready. Unlock to pay.</p>;
}unlock(password) must be passed directly to pay({ secret, ... }). Never log it, never store it in useState, and never send it to a server. Only the commitment hash (Poseidon(LEAF_TAG, secret)) is transmitted to the backend API.4Execute ZK Payment
useFluppyPayment orchestrates the full ZK payment flow: Merkle proof → Groth16 proof → Freighter signing → Soroban contract. It reads the SDK configuration from FluppyProvider.
'use client';
import { useFluppyCredential, useFluppyPayment, useFluppyHistory } from '@fluppy/react';
export function PaymentForm({ merchantAddress }: { merchantAddress: string }) {
const cred = useFluppyCredential();
const payment = useFluppyPayment();
const history = useFluppyHistory();
async function handlePay(password: string) {
// Step 1: Unlock credential — get secret in memory only
const secret = await cred.unlock(password);
// Step 2: Execute ZK payment — secret is passed through, never stored
const result = await payment.pay({
secret,
merchant: merchantAddress,
amount: 10_000_000n, // 1 USDC in stroops (1 USDC = 10_000_000)
});
// Step 3: Record in local history
history.add({
txHash: result.txHash,
amount: 10_000_000n,
merchant: merchantAddress,
timestamp: Date.now(),
status: 'success',
explorerUrl: `https://stellar.expert/explorer/testnet/tx/${result.txHash}`,
});
}
return (
<div>
{payment.status === 'pending' && (
<div>
<p>Step: {payment.currentStep}</p>
<p>Progress: {payment.progressPct ?? 0}%</p>
<p>Stage: {payment.progressStage}</p>
</div>
)}
{payment.txHash && (
<p>Confirmed: {payment.txHash}</p>
)}
{payment.error && (
<p>Error: {payment.error.message}</p>
)}
<button
onClick={() => handlePay('user-password')}
disabled={payment.isLoading}
>
{payment.isLoading ? 'Processing...' : 'Pay 1 USDC'}
</button>
</div>
);
}| State | Type | Description |
|---|---|---|
| status | PaymentStatus | idle | pending | success | failed |
| progressPct | number | null | 0–100 during proof generation |
| progressStage | string | null | Current proof stage label |
| currentStep | FluppyPaymentStepName | merkle:request | proof:start | tx:submit | ... |
| txHash | string | null | Transaction hash on success |
| error | Error | null | Structured error on failure |
| pay(input) | Promise<Result> | Initiates payment; throws on failure |
| abort() | () => void | Cancels in-flight payment, resets to idle |
| reset() | () => void | Full state reset to idle |
5Display Payment History
useFluppyHistory persists payment records to localStorage under the key fluppy:payment-history:v1. The amount field is serialized as a decimal string internally — the public API always exposes bigint. Records persist across page reloads and are capped at 50 entries.
'use client';
import { useFluppyHistory } from '@fluppy/react';
export function PaymentHistory() {
const { records, clear } = useFluppyHistory();
if (records.length === 0) return <p>No payments yet.</p>;
return (
<div>
<ul>
{records.map((record) => (
<li key={record.txHash}>
<span>{record.status}</span>
<span>
{(Number(record.amount) / 10_000_000).toFixed(2)} USDC
</span>
<a
href={record.explorerUrl}
target="_blank"
rel="noopener noreferrer"
>
{record.txHash.slice(0, 8)}...
</a>
</li>
))}
</ul>
<button onClick={clear}>Clear history</button>
</div>
);
}6Security Reminders
Never log the secret
The 64-char hex secret from unlock() must be passed directly to pay(). Logging it to console or sending it to an API breaks the privacy model.
Never store the secret in React state
useState persists across renders. Pass the secret directly from unlock() to pay() in the same async function. Do not store it in a ref or global variable either.
User signs and pays network fee via Freighter
There is no production relayer in the current MVP. The user approves and signs the Soroban transaction directly through the Freighter browser extension.
Protocol fee is taken from the payment amount
The Soroban contract autonomously splits the payment: 95% to the merchant, 5% to the protocol treasury. This is not an additional charge — it comes from the amount you pass to pay().
This is a Testnet MVP
No real funds are at risk on Testnet. Do not use mainnet USDC until a full security audit, multi-party trusted setup, and native BN254 pairing verification are complete.