Send USDC with the Peer SDK
A send pays someone in their own payment app from your Base USDC. In @zkp2p/sdk it is one peer.sell() call whose payee is the recipient's handle instead of your own. Peer buyers pay the recipient in fiat, prove the payment, and take the USDC. The recipient needs no Peer account, wallet or crypto.
The Peer mobile and web apps call peer.sell.prepare() and submit the resulting transactions through the user’s wallet. For the user-facing walkthrough, see Send USDC to any payment app.
Why it suits agents
- Recipient details: choose the platform and currency, enter the amount, and supply the handle from the table below. Alipay also needs a name character for a new recipient. No bank details, KYC flow or API key.
- Discovery without a network call:
peer.sell.capabilities()lists supported platforms and currencies. Use the recipient table for the handle each platform accepts. - Checked before funds move where the app allows it: for Venmo, Cash App, Revolut, Monzo, PayPal, Wise and X Money, an unknown username can return
PAYEE_NOT_FOUNDduring registration. An existing X username still needs X Money enabled. - Unsigned plans:
peer.sell.prepare()returns labelled transactions for agent wallets, smart accounts and policy engines. - Typed errors: use
isPeerError(error)before readingcode,retryableorremediation. Input helpers can throw ordinary errors, for exampleusdc("0.0000001")exceeds six decimal places. - Resumable: the returned
depositIdalone rebuilds the send's state from chain and indexer data.
Installation
npm install @zkp2p/sdk viem
Use @zkp2p/sdk 0.16.2 or later with viem ^2.37.3, on Node 22 or newer.
Quick start
import { createPeer, isPeerError, usdc } from "@zkp2p/sdk";
const peer = createPeer({ environment: "production", referrer: "your-app" });
try {
const send = await peer.sell(
{
amount: usdc(50),
receive: { platform: "venmo", currency: "USD", payee: "@alex-smith" },
},
{ signer }, // a viem WalletClient on Base holding the USDC
);
await saveSend({ userId, depositId: send.depositId, txHash: send.txHash });
for await (const order of peer.sell.watch(send.depositId)) {
console.log(order.state, order.explain());
}
} catch (error) {
if (!isPeerError(error)) throw error;
console.error(error.code, error.remediation);
}
The call registers the recipient's handle, approves and deposits the USDC, and returns once the deposit confirms. Persist depositId right away. Everything else on this page uses the same API as selling USDC; the Sell integration guide covers each method in depth.
Recipient handles
Pass the platform id as receive.platform and the handle as receive.payee. The SDK strips a leading @, $ or paypal.me/ where the platform allows it.
| Platform | platform | payee | Currencies |
|---|---|---|---|
| Venmo | venmo | Venmo username, e.g. "@alex-smith" | USD |
| Cash App | cashapp | Cashtag, e.g. "$alexsmith" | USD |
| Zelle | zelle | Email enrolled with Zelle, e.g. "alex@example.com" | USD |
| Chime | chime | ChimeSign, e.g. "$alexsmith" | USD |
| PayPal | paypal | PayPal.Me username, e.g. "paypal.me/alexsmith" (not the email) | USD, EUR, GBP, CAD, AUD, NZD, SGD |
| X Money | xmoney | X username with X Money on, e.g. "@alexsmith" | USD |
| Wise | wise | Wisetag, e.g. "@alexs" | USD, EUR, GBP, CAD, AUD, NZD, SGD, CHF, MXN, INR, IDR, PHP, CNY, TRY, ZAR |
| Revolut | revolut | Revtag, e.g. "alexs12" | USD, EUR, GBP, CAD, AUD, NZD, SGD, CHF, MXN, CNY, TRY, ZAR |
| Monzo | monzo | Monzo.me username, e.g. "alexsmith" | GBP |
| UPI | upi | UPI ID with a supported suffix, e.g. "alex@okaxis" | INR |
| Alipay | alipay | { offchainId: "<16-digit account ID>", metadata: { alipayFirstName: "<first character of real name>" } } | CNY |
This is the production list as of SDK 0.17.0. Read platforms and currencies from the installed SDK:
for (const p of peer.sell.capabilities().platforms) {
console.log(p.platform, p.currencies);
}
New registrations check that Venmo, Cash App, Revolut, Monzo, PayPal, Wise and X usernames exist. For X Money, confirm with the recipient that their account can receive payments. Zelle, Chime, UPI and Alipay check the identifier format only. UPI also requires a supported suffix such as @okaxis or @ybl; ask for the ID shown in the recipient's UPI app.
SDK 0.17.0's payeeHint suggests a phone number for Zelle and an email for Alipay. For Zelle, collect an enrolled email. For Alipay, use the account ID and name below.
Alipay
An Alipay recipient is their 16-digit account ID, which starts with 2088, plus the first character of their real name. Alipay asks the buyer to confirm that name when they pay.
await peer.sell(
{
amount: usdc(100),
receive: {
platform: "alipay",
currency: "CNY",
payee: {
offchainId: "2088012345678901",
metadata: { alipayFirstName: "张" },
},
},
},
{ signer },
);
A new account ID without alipayFirstName fails with PAYEE_REGISTRATION_FAILED, and an email address is refused. An account ID that Peer already knows can be sent to without the name. In SDK 0.17.0, capabilities() still reports requiresIdentityAttestation: true for Alipay; an account ID doesn't need one, so don't filter Alipay out on that flag.
Speed
Price a send below the market so buyers take it sooner. premiumBps runs from 0 to MAX_SELL_PREMIUM_BPS (100, so 1%). The Peer apps use three speeds:
| Speed | premiumBps | Recipient gets |
|---|---|---|
| Standard | 0 | The market amount |
| Faster | 50 | About 0.5% less |
| Fastest | 100 | About 1% less |
await peer.sell(
{
amount: usdc(50),
receive: { platform: "wise", currency: "EUR", payee: "@alexs" },
premiumBps: 50,
},
{ signer },
);
That deposits exactly 50 USDC and the recipient gets about 0.5% less fiat. To keep the recipient's amount the same instead, deposit sellAmountForPremium(usdc(50), 50).
To speed up a live send while keeping the USDC fixed, build peer.sell.prepareSpeedUp(depositId, 100, { fund: false }) and submit its transactions in order. Without { fund: false }, the plan tops up the USDC so the recipient's amount stays the same. See Pay a premium to fill sooner.
Agent wallets and unsigned plans
For an ERC-4337 smart account, submit each prepared call as its own user operation. The example uses a viem bundler client and smart account configured for Base. Store each operation hash with your send request before waiting, so a timeout can be reconciled by hash.
import { getContracts } from "@zkp2p/sdk";
import { pad, parseEventLogs } from "viem";
const { abis } = getContracts(8453, "production");
const plan = await peer.sell.prepare({
amount: usdc(50),
receive: { platform: "revolut", currency: "GBP", payee: "alexs12" },
});
for (const [i, { to, data, value }] of plan.txs.entries()) {
const step = plan.steps[i].kind;
const hash = await bundlerClient.sendUserOperation({
account,
calls: [{ to, data, value }],
});
await saveOperation({ requestId, step, hash });
const op = await bundlerClient.waitForUserOperationReceipt({ hash });
if (!op.success || op.receipt.status !== "success") {
throw new Error(`${step} failed: ${hash}`);
}
if (step === "createDeposit") {
// DepositReceived indexes the depositor in topics[2].
const depositorTopic = pad(account.address).toLowerCase();
const logs = parseEventLogs({
abi: abis.escrowV2 ?? abis.escrow,
eventName: "DepositReceived",
logs: op.logs,
}).filter((log) => log.topics[2]?.toLowerCase() === depositorTopic);
const send = peer.sell.finalizePrepared({
transactionHash: op.receipt.transactionHash,
status: op.receipt.status,
logs,
});
await saveSend({
requestId,
depositId: send.depositId,
txHash: send.txHash,
});
}
}
Use the deposit operation's logs. The outer transaction receipt can include other senders' deposits, even when your own operation failed. If the receipt is missing or the deposit cannot be resolved, use the saved hash to reconcile before retrying.
prepare() registers the handle first, and rejects unsupported input before signing. Skip approve when the allowance already covers the amount.
A checklist for an agent that sends on a user's behalf:
- Use
capabilities()for platforms and currencies and the recipient table for accepted handles. For Alipay, collect the 16-digit2088account ID and the first character of the real name. - Show
peer.sell.estimate({ amount, currency, platform })as approximate. Each buyer's rate binds when they take part of the send. - On
PAYEE_NOT_FOUND, ask for a corrected handle; retrying the same input fails again. - For Zelle, Chime, UPI and Alipay, read the platform, handle, currency and amount back to the user and get explicit confirmation before funding. Do the same for X Money and confirm the recipient has enabled payments.
- Save
depositIdas soon as the call returns. - On
TRANSACTION_SUBMISSION_UNKNOWNorTRANSACTION_STATUS_UNKNOWN, don't send again yet. Check the original transaction in the wallet or by its receipt (error.recovery.transactionHashwhen present) and checkpeer.sell.orders(owner). An emptyorders()alone doesn't make a retry safe: the original may still be pending or the indexer may be behind. Send again only after the original is confirmed failed or cancelled; while it is pending or unclear, wait. - Report progress from
order.stateandorder.explain().
Several recipients
Each recipient is its own send. Call peer.sell() once per recipient and save each depositId; the web app sends to up to 5 recipients this way.
Track and cancel
| State | Meaning |
|---|---|
awaiting-buyer | Live, no buyer yet |
matched | A buyer is paying the recipient now |
delivering | Part is paid and more is in progress |
delivered | The recipient was paid and the USDC released |
returned | The unpaid USDC came back to the sender |
While a buyer has funds locked, you can withdraw the unlocked balance by passing an explicit amount in USDC base units:
const order = await peer.sell.order(depositId);
const amount =
order.totalAmount -
order.filledAmount -
order.pendingAmount -
order.returnedAmount;
if (amount > 0n) {
await peer.sell.withdraw(depositId, { signer, amount });
}
For an unsigned withdrawal, use peer.sell.prepareWithdraw(depositId, { amount }) with the same positive amount. Omitting amount requests a full close and raises ACTIVE_INTENT_BLOCKS_WITHDRAWAL while a buyer's intent is live. Reconcile with the verified fiatPaid, paidCurrency and paidAt of each fill, not with the estimate.
Fees and limits
- Peer charges the sender no fee. Buyers pay Peer's service fee on their side.
- The SDK accepts sends from 0.01 USDC with no upper bound; 1 USDC or more is recommended so buyers can fill it. The Peer apps allow 1 to 1,000 USDC per recipient.
- By default a buyer can take from 1 USDC up to the whole send. To make one buyer pay it all, set
intentAmountRange; see Order sizing.
Test first
Point environment at "staging" and run a 1–2 USDC send to your own handle, then cancel it with withdraw(). The staging checklist covers each step.