Skip to main content

Sell USDC with the Peer SDK

createPeer() in @zkp2p/sdk is the Peer SDK's front door. peer.sell() sells Base USDC for fiat that arrives in the seller's own payment app. Use it in a wallet, app, Node service, or agent.

The seller is the maker. peer.sell() creates a Base USDC deposit at the live market rate. A buyer signals an intent, pays the seller in fiat, and proves the payment with TEE-TLS. The protocol then releases the matching USDC to the buyer.

Release candidate

createPeer() ships in @zkp2p/sdk@0.16.0-rc.1 on the npm rc tag. The latest tag still points to 0.15.x, so pin the exact version. Moving from @zkp2p/cash? Read Migrate from @zkp2p/cash.

peer.sell() or the client reference?​

Both live in @zkp2p/sdk.

peer.sell()Zkp2pClient
Best forA cash-out productA custom protocol integration
User roleSeller (maker) onlyMaker, taker, or both
PricingOn-chain oracle rate when a buyer signals, zero spreadSet by your integration
AssetBase USDCProtocol 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

Choose peer.sell() when selling USDC for fiat is the product. It has no API for custom spreads, disputes, seller-credential uploads, vaults, delegated rate management, or arbitrary contract calls. For those, use the client reference.

The same client buys USDC with peer.buy. This guide covers selling only. In 0.16.0-rc.1, the full live purchase (signal, pay, and PeerAuth proof) has not been proven on a live network; peer.buy ships on a live staging quote and unit tests.

How a sale works​

Base USDC in the seller's wallet
│
│ peer.sell(): deposit at zero spread
▼
Buyer signals an intent
│
│ buyer pays the seller 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 seller can withdraw unmatched funds at any time, and withdraw() prunes expired buyer intents first.

Installation​

npm install @zkp2p/sdk@0.16.0-rc.1 viem
# or
yarn add @zkp2p/sdk@0.16.0-rc.1 viem
# or
pnpm add @zkp2p/sdk@0.16.0-rc.1 viem
# or
bun add @zkp2p/sdk@0.16.0-rc.1 viem

The package needs Node 22 or newer and viem ^2.37.3, a peer dependency. It ships ESM and CommonJS builds.

Quick start​

import { createPeer, isPeerError, usdc } from "@zkp2p/sdk";

const peer = createPeer({ environment: "production" });

const venmo = peer.sell
.capabilities()
.platforms.find(({ platform }) => platform === "venmo");

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

const estimate = await peer.sell.estimate({
amount: usdc(25),
currency: "USD",
platform: "venmo",
});

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

try {
const sale = await peer.sell(
{
amount: usdc(25),
receive: { platform: "venmo", currency: "USD", payee: "@your-venmo" },
},
{ signer },
);

await saveSale({
userId,
depositId: sale.depositId,
transactionHash: sale.txHash,
});

for await (const order of peer.sell.watch(sale.depositId)) {
console.log(order.state, order.explain());
}
} catch (error) {
if (!isPeerError(error)) throw error;
console.error(error.code, error.remediation);
}

signer is a viem WalletClient on Base with an account. peer.sell() registers the payee, approves and deposits the USDC, and returns once the deposit confirms. Persist depositId right away: it is the resume key for order(), watch(), topUp(), and withdraw().

One sale 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 sellerNone

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

Attribution​

Every transaction peer.sell() builds carries ERC-8021 attribution, starting with peer-cash, so Peer's indexer classifies SDK sales like earlier cash-outs. 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. To show your label and logo on your deposits in Peer's order books, pass brand; see Show your brand on your deposits.

Optional receipt linking​

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

Next step​

Continue to the integration guide for signed and unsigned transaction paths, error recovery, and staging verification.