@fluppy/react
React SDK built on @fluppy/browser. Provides a context provider and four domain hooks for the full Fluppy payment lifecycle.
@fluppy/react is complete as an SDK layer. Full migration of the existing Fluppy app to these hooks is a planned next phase. These hooks are ready to be consumed by any React 18+ application with FluppyProvider at the root.Available Hooks
FluppyProviderContext provider ā wraps a React subtree with Fluppy config
useFluppyCredentialCredential lifecycle: create, unlock, delete, status
useFluppyPaymentFull ZK payment flow with abort, progress, and step tracking
useFluppyWalletFreighter wallet connection state (SSR-safe, dynamic import)
useFluppyHistorylocalStorage-persisted payment records with bigint serialization
FluppyProvider
Wrap your application (or a subtree) with FluppyProvider. All Fluppy hooks must be descendants of this provider. Memoize the config object to prevent unnecessary re-renders.
| Config field | Type | Description |
|---|---|---|
| stellarConfig | StellarConfig | contractId, rpcUrl, networkPassphrase ā Soroban connection config |
| networkPassphrase | string | Stellar network passphrase ā MUST match the contract's expected chainId |
| merkleOptions? | MerkleClientOptions | Optional: apiBaseUrl override for the Merkle proof backend |
import { FluppyProvider } from '@fluppy/react';
const config = {
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!,
};
export default function Layout({ children }: { children: ReactNode }) {
return <FluppyProvider config={config}>{children}</FluppyProvider>;
}useFluppyCredential()
Manages the full lifecycle of a locally encrypted ZK credential. Initial credential check runs in a browser-safe useEffect ā SSR renders return status: 'unknown'.
secret returned by create() and unlock() must never be logged, never stored in useState, and never sent to any server. Pass it directly to useFluppyPayment().pay() in the same async function.| Property | Type | Description |
|---|---|---|
| status | CredentialStatus | unknown | exists | not_found |
| exists | boolean | null | true/false when status is known; null while unknown |
| isLoading | boolean | True during any async credential operation |
| error | Error | null | Last thrown error; null if none |
| create(pw) | (string) ā Promise<{secret}> | Creates and encrypts a new credential; returns secret ONCE |
| unlock(pw) | (string) ā Promise<string> | Decrypts and returns raw secret ā never logged internally |
| remove() | () ā Promise<void> | Permanently deletes credential from IndexedDB |
| refresh() | () ā Promise<void> | Re-checks credential existence |
| resetError() | () ā void | Clears current error without changing status |
useFluppyPayment()
Orchestrates the full ZK payment flow. Reads configuration from FluppyProvider. The secret is passed as a parameter to pay() ā it is never stored in React state.
| State | Type | Description |
|---|---|---|
| status | PaymentStatus | idle | pending | success | failed |
| isLoading | boolean | True during proof generation or transaction submission |
| error | Error | null | Last thrown error; null if none |
| txHash | string | null | Transaction hash on success; null otherwise |
| progressStage | string | null | Current proof generation stage label (e.g. "Computing witness") |
| progressPct | number | null | 0ā100 during proof generation |
| currentStep | FluppyPaymentStepName | null | Named orchestrator step: merkle:request | proof:start | tx:submit | tx:confirmed | ... |
| Method | Returns | Description |
|---|---|---|
| pay(input) | Promise<ExecuteFluppyPaymentResult> | Initiates payment; throws on failure ā caller handles UI feedback |
| abort() | void | Cancels in-flight payment, resets status to idle |
| reset() | void | Full state reset: clears status, error, txHash, progress |
| resetError() | void | Clears error only ā preserves txHash and status |
| pay() input | Type | Description |
|---|---|---|
| secret | string | 64-char hex from useFluppyCredential.unlock() ā NOT stored in state |
| merchant | string | Merchant Stellar address (G... format) |
| amount | bigint | Payment amount in stroops (1 USDC = 10_000_000n) |
| signal? | AbortSignal | Optional external abort signal composed with the hook's own controller |
useFluppyWallet()
Manages Freighter wallet connection state. Uses dynamic import for the Freighter API to avoid bundling it in SSR contexts. refresh() is a no-op on the server.
| Property | Type | Description |
|---|---|---|
| address | string | null | Connected Stellar address; null if not connected |
| connectionStatus | WalletConnectionStatus | disconnected | connecting | connected | error |
| isConnected | boolean | Derived: true when status is connected |
| isConnecting | boolean | Derived: true when status is connecting |
| error | Error | null | Last error from connect(); null if none |
| connect() | () ā Promise<string> | Calls Freighter requestAccess(), returns address; throws on rejection |
| refresh() | () ā Promise<void> | Re-checks Freighter isConnected(); no-op on SSR |
| resetError() | () ā void | Clears error only |
useFluppyHistory()
Persists payment record metadata to localStorage using the key fluppy:payment-history:v1. Records are loaded on mount inside a browser-safe useEffect ā SSR renders return an empty array. Capped at 50 records.
amount is a bigint in the public API but serialized as a decimal string in localStorage (JSON cannot encode bigint natively). Deserialization is handled automatically ā callers always receive bigint. No secrets, passwords, ZK proof internals, or private keys are stored.| Method | Signature | Description |
|---|---|---|
| add(record) | (FluppyPaymentRecord) ā void | Prepends record; deduplicates by txHash; persists |
| update(txHash, patch) | (string, Partial) ā void | Updates matching record fields; persists |
| remove(txHash) | (string) ā void | Removes record by txHash; persists |
| clear() | () ā void | Clears all records from state and localStorage |
| refresh() | () ā void | Reloads records from localStorage |
| FluppyPaymentRecord field | Type | Description |
|---|---|---|
| txHash | string | Stellar transaction hash |
| amount | bigint | Payment amount in stroops |
| merchant | string | Merchant Stellar address |
| timestamp | number | Unix timestamp in milliseconds |
| status | 'pending' | 'success' | 'failed' | Payment outcome |
| explorerUrl? | string | Optional Stellar Expert explorer URL |
Combined Example
'use client';
import {
useFluppyCredential,
useFluppyPayment,
useFluppyHistory,
useFluppyWallet,
} from '@fluppy/react';
export function PaymentCard({ merchant }: { merchant: string }) {
const wallet = useFluppyWallet();
const cred = useFluppyCredential();
const payment = useFluppyPayment();
const history = useFluppyHistory();
async function handlePay(password: string) {
if (!wallet.isConnected) await wallet.connect();
// unlock() returns secret in memory only ā NOT stored in state
const secret = await cred.unlock(password);
const result = await payment.pay({
secret,
merchant,
amount: 10_000_000n, // 1 USDC
});
// Store metadata ā NOT secret, NOT proof internals
history.add({
txHash: result.txHash,
amount: 10_000_000n,
merchant,
timestamp: Date.now(),
status: 'success',
explorerUrl: `https://stellar.expert/explorer/testnet/tx/${result.txHash}`,
});
}
return (
<div>
{payment.status === 'pending' && (
<div>
<div>{payment.currentStep}</div>
<div>{payment.progressPct ?? 0}% ā {payment.progressStage}</div>
</div>
)}
{payment.status === 'success' && <p>ā {payment.txHash}</p>}
{payment.error && <p>Error: {payment.error.message}</p>}
<button
onClick={() => handlePay(passwordFromSecureInput)}
disabled={payment.isLoading}
>
Pay 1 USDC
</button>
</div>
);
}