Skip to main content

Peer Cash SDK

@zkp2p/cash is Peer's offramp-only TypeScript SDK. Use it in a wallet, app, Node service, or agent to cash out Base USDC to a fiat payment platform. Assets on other chains can be routed into Base USDC first.

The cashing-out user is the maker. They create a Base USDC deposit at the live market rate. A buyer signals an intent, pays the user in fiat, and proves the payment with TEE-TLS. The protocol then releases the matching USDC to the buyer.

Peer Cash SDK or ZKP2P SDK?​

Peer Cash SDKZKP2P SDK
Package@zkp2p/cash@zkp2p/sdk
Best forA cash-out productA custom protocol integration
User roleMaker onlyMaker, taker, or both
PricingOn-chain oracle rate when a buyer signals, zero spreadSet by your integration
Asset pathBase USDC, or another asset routed into Base USDC through Relay or NEAR IntentsProtocol and API primitives you choose
WorkflowBuilt-in order lifecycle with typed recoveryDeposits, intents, fulfillment, quotes, proofs, vaults, rate managers, hooks
Signingviem signer or unsigned Base USDC transaction plansDirect and prepared protocol transactions
React@zkp2p/cash/react@zkp2p/sdk/react
Agent toolingJSON-schema tool manifest in @zkp2p/cash/toolsBuild your own

Choose Peer Cash when cash-out is the product. It has no API for custom spreads, buyer-side intents or proofs, disputes, seller-credential uploads, vaults, delegated rate management, or arbitrary contract calls. For those, use the ZKP2P SDK.

How a cash-out works​

Optional source asset
│
│ Relay or NEAR Intents route
▼
Base USDC deposit at zero spread
│
│ buyer signals an intent
▼
Buyer pays the maker through a supported fiat app
│
│ TEE-TLS payment proof
▼
Protocol releases USDC to the buyer

The protocol contracts hold the funds; the SDK never holds keys. The maker can withdraw unmatched funds at any time, and withdraw() prunes expired buyer intents first.

Installation​

npm install @zkp2p/cash viem
# or
yarn add @zkp2p/cash viem
# or
pnpm add @zkp2p/cash viem
# or
bun add @zkp2p/cash viem

The current stable release is @zkp2p/cash@0.7.3. It needs Node 22 or newer and viem 2.37.3 or newer within 2.x. React 18 or newer is an optional peer dependency, used only by @zkp2p/cash/react.

Cash 0.7.3 pins @zkp2p/sdk@0.14.10. If your app also depends on @zkp2p/sdk, use the same version so one copy resolves.

Quick start​

import { createCashClient, usdc } from "@zkp2p/cash";

const cash = createCashClient({ environment: "production" });

const chime = cash
.capabilities()
.platforms.find(({ platform }) => platform === "chime");

if (!chime?.currencies.includes("USD")) {
throw new Error("Chime USD is not available in this environment");
}

const estimate = await cash.estimate({
amount: usdc(100),
currency: "USD",
platform: "chime",
});

console.log(`Approximately ${estimate.receiveAmount} USD`);

const result = await cash.cashout(
{
amount: usdc(100),
receive: {
platform: "chime",
currency: "USD",
payee: { offchainId: "$your-chime-sign" },
},
},
{ signer },
);

await saveCashOrder({
userId,
depositId: result.depositId,
transactionHash: result.txHash,
});

signer is a viem WalletClient on Base with an account. Persist depositId right away: it is the resume key for order(), watch(), topUp(), and withdraw().

Venmo and PayPal on 0.7.3

In 0.7.3, cashout() attaches the retired Peer Pay merchant group to Venmo and PayPal deposits. Create those cash-outs with prepare() instead. See Protected payout rails.

One order can offer several ways to get paid: a leg can list several currencies, and receive accepts an array of legs on different platforms. Every option fills at its live zero-spread oracle rate. See Offer several currencies or platforms.

An estimate is not a locked quote

estimate() reads the current oracle rate and can include a historical fill-time estimate. Each buyer's rate binds when they signal an intent. Show the value as approximate, honor estimate.stale, and don't present the ETA as a guarantee.

The lifecycle​

The SDK rebuilds every order state from protocol data.

StateMeaningTypical next action
awaiting-buyerThe deposit is live and no buyer has an active intentWait, top up, or withdraw
matchedA buyer has signaled and the matching USDC is lockedWait for payment and proof, or for the intent to expire
deliveringPart of the order is fulfilled and more remains activeKeep observing
deliveredFiat was proven and the filled USDC was releasedReconcile the verified fill data
returnedRemaining funds were withdrawn to the makerNone

Use order.nextActions (wait, withdraw) and order.explain() instead of tracking state yourself. watch(depositId) yields changes until the order reaches a terminal state. orders(owner, { inFlight: true }) lists a wallet's active orders.

Purpose-built entry points​

Entry pointUse it for
@zkp2p/cashDiscovery, estimates, signed operations, unsigned plans, order reads, codecs, and typed errors
@zkp2p/cash/reactuseEstimate, useCashout, useOrder, and useOrders
@zkp2p/cash/toolsJSON-schema tool definitions for an agent host, CLI, or policy-controlled signer

Every transaction the SDK builds carries ERC-8021 attribution, starting with peer-cash. Add your own analytics codes with referrer. To earn Peer's integration share on the flow you bring, pass your Peer referral code as referralCode; see Earn from the flow you bring.

Optional receipt linking​

Venmo and X Money users can link the inbox that receives their payment receipts through a page Peer hosts. Linking is a separate step: cashout() and prepare() never invoke or require it. See Optional Venmo receipt linking.

Next step​

Continue to the integration guide for signed and unsigned transaction paths, Relay source routing, React hooks, error recovery, and staging verification.