Migrate from @zkp2p/cash
peer.sell() in @zkp2p/sdk@0.16.0-rc.1 carries over the @zkp2p/cash sell engine. Sales create the same zero-spread Base USDC deposit, keep the same peer-cash ERC-8021 attribution, and resume from the same depositId, so orders created with Cash can be read, watched, topped up, and withdrawn with peer.sell.
@zkp2p/cash stays published, so existing installs keep working. Move when you're ready, and keep Cash for any feature in Not in the SDK.
Install
npm uninstall @zkp2p/cash
npm install @zkp2p/sdk@0.16.0-rc.1 viem
0.16.0-rc.1 is on the npm rc tag; latest still points to 0.15.x, so pin the exact version. It needs Node 22 or newer and viem ^2.37.3.
Before and after
// Before: @zkp2p/cash
import { createCashClient, isCashError, usdc } from "@zkp2p/cash";
const cash = createCashClient({ environment: "production" });
const result = await cash.cashout(
{
amount: usdc(25),
receive: { platform: "venmo", currency: "USD", payee: "@alice" },
},
{ signer },
);
for await (const order of cash.watch(result.depositId))
console.log(order.state);
// After: @zkp2p/sdk
import { createPeer, isPeerError, usdc } from "@zkp2p/sdk";
const peer = createPeer({ environment: "production" });
const sale = await peer.sell(
{
amount: usdc(25),
receive: { platform: "venmo", currency: "USD", payee: "@alice" },
},
{ signer },
);
for await (const order of peer.sell.watch(sale.depositId))
console.log(order.state);
Client and methods
@zkp2p/cash | @zkp2p/sdk |
|---|---|
createCashClient(options) | createPeer(options), then use peer.sell |
cash.cashout(input, { signer }) | peer.sell(input, { signer }) (the method is callable) |
cash.prepare(input) | peer.sell.prepare(input) |
cash.finalizePreparedCashout(receipt) | peer.sell.finalizePrepared(receipt) |
cash.capabilities() | peer.sell.capabilities() |
cash.estimate(), cash.fillStats() | peer.sell.estimate(), peer.sell.fillStats() |
cash.order(), cash.orders(), cash.watch(), cash.buyer() | peer.sell.order(), peer.sell.orders(), peer.sell.watch(), peer.sell.buyer() |
cash.withdraw(), cash.prepareWithdraw() | peer.sell.withdraw(), peer.sell.prepareWithdraw() |
cash.topUp(), cash.prepareTopUp() | peer.sell.topUp(), peer.sell.prepareTopUp() |
Apart from the intended differences and the features not carried over, method inputs and results keep their shapes. createPeer() keeps these options: environment, transport, rpcUrl, indexerUrl, indexerApiKey, curatorUrl, apiKey, referralCode, brand, and referrer. It drops peerOrigin, venmoGmail, xmoney, sarConnect, relay, and nearIntents. Its new getAuthorizationToken option is used only by peer.buy.
Errors and constants
@zkp2p/cash | @zkp2p/sdk |
|---|---|
CashError | PeerError |
isCashError | isPeerError |
CashErrorCode | PeerErrorCode |
CashErrorShape | PeerErrorShape |
CashErrorRecovery | PeerErrorRecovery |
isUserRejectedError | isUserRejectedError |
CASH_ATTRIBUTION_CODE | SELL_ATTRIBUTION_CODE (still "peer-cash") |
toCashReferralAttributionCode | toSellReferralAttributionCode |
toCashBrandAttributionCode | toSellBrandAttributionCode |
MIN_CASHOUT_AMOUNT | MIN_SELL_AMOUNT |
RECOMMENDED_MIN_CASHOUT_AMOUNT | RECOMMENDED_MIN_SELL_AMOUNT |
usdc, formatUsdc | usdc, formatUsdc |
CurrencyType, RuntimeEnv, and PreparedTransaction are exported from @zkp2p/sdk.
The recovery kind inspect-base-cashout-submission is now inspect-base-sale-submission, with the same amount and depositor fields. The source-route recovery kinds, every SOURCE_* error code and INDEXER_LAG are gone.
Types
@zkp2p/cash | @zkp2p/sdk |
|---|---|
CashClient | PeerSell (or Peer["sell"]) |
CashoutInput | SellInput |
CashoutResult | SellResult |
PrepareResult | SellPrepareResult |
PreparedCashoutReceipt | PreparedSellReceipt |
CashPreparedStep | SellPreparedStep |
CashOrder | SellOrder |
CashOrderState | SellOrderState |
CashFill | SellFill |
CashCapabilities | SellCapabilities |
CashPlatformCapability | SellPlatformCapability |
CashEstimate | SellEstimate |
EstimateInput | SellEstimateInput |
EstimateOptions | SellEstimateOptions |
CashFillStats | SellFillStats |
CashFillEta | SellFillEta |
CashLeg | SellLeg |
CashMultiCurrencyLeg | SellMultiCurrencyLeg |
CashReceiveLeg | SellReceiveLeg |
CashPayeeInput | SellPayeeInput |
CashBuyerProfile | SellBuyerProfile |
WithdrawResult | SellWithdrawResult |
WithdrawOptions | SellWithdrawOptions |
TopUpResult | SellTopUpResult |
WatchOptions | SellWatchOptions |
OrdersOptions | SellOrdersOptions |
SignerOptions | SignerOptions |
Intended differences
Compared side by side with @zkp2p/cash 0.8.2 on staging, peer.sell differs here, beyond the renames above and the features in Not in the SDK:
| Surface | @zkp2p/cash 0.8.2 | @zkp2p/sdk peer.sell |
|---|---|---|
| A payee that doesn't resolve on its platform (an unknown Wisetag, PayPal.Me, Venmo, Revolut, or Cash App handle) | PAYEE_REGISTRATION_FAILED, retryable: true | PAYEE_NOT_FOUND, retryable: false |
capabilities() | Includes source and destination | No source or destination; every sale is Base USDC in and fiat out |
error.recovery.operation for the sale itself (submission, receipt, and deposit resolution) | 'cashout' | 'sell'; approve, withdraw, and top-up operations keep their names |
Error message and remediation text | Worded for Cash, such as "Use cashout()…" | Reworded throughout, such as "Use peer.sell()…"; every code is kept |
Branch on code and recovery.kind, never on message, remediation or recovery.operation text. Retrying the same handle after PAYEE_NOT_FOUND can't succeed, so ask the user for a corrected handle instead of retrying. If your code retried every PAYEE_REGISTRATION_FAILED, handle PAYEE_NOT_FOUND separately.
Behaviour otherwise matched: estimates, every input-validation code, PAYEE_VERIFICATION_REQUIRED for a new Alipay handle, order() and watch() through delivered and returned, orders(), fillStats(), withdraw and top-up state checks, and signer errors. The createDeposit calldata was byte-identical, including the peer-cash attribution.
Not in the SDK
These @zkp2p/cash features were not carried over. Keep @zkp2p/cash for them, or build them on the SDK primitives named here.
@zkp2p/cash feature | With @zkp2p/sdk |
|---|---|
Relay and NEAR Intents source routing: quoteSource, executeSourceQuote, relayStatus, cashout() with source, capabilities({ includeRelaySources }) | Not available. Route the asset into Base USDC yourself, then call peer.sell(). |
Receipt-linking helpers: prepareVenmoGmailConnect, isVenmoGmailConnected, prepareXMoneyConnect, and related methods | Use registerPayeeDetails(), openVenmoGmailConnect() or getVenmoGmailConnectUrl(), openXMoneyConnect() or getXMoneyConnectUrl(), and getSellerCredentialStatus(). See Optional receipt linking. |
Cash App and PayPal App Clip account connection: prepareSarConnect and related methods | Not available. |
Codecs: zod schemas and *ToJson / *FromJson, such as orderToJson and prepareResultToJson | Not available. Use a bigint-safe JSON.stringify replacer; see Serialize across process boundaries. |
React hooks from @zkp2p/cash/react | Not available. Call peer.sell methods from your own hooks. |
Agent tool manifest from @zkp2p/cash/tools | Not available. Wrap peer.sell.prepare() and the other prepare methods in your host's tools. |
Pure engine helpers: deriveCashOrder, deriveBuyerProfile, derivePayouts, explainOrder, withExplain, isFillLive, isMarketRateSupported, buildCapabilities, buildIntentAmountRange, buildMarketRateCurrencyOverride, prepareCashDepositParams, parseCompositeDepositId, resolveCashDepositId, normalizeCashPayee, centsToNumber, fiatFromUsdc, fiatToNumber, rateToNumber | Not exported. Use the peer.sell methods that wrap them: order(), orders(), watch() and buyer() derive order state, capabilities() replaces buildCapabilities, prepare() builds deposit params, and finalizePrepared() resolves a deposit id from a receipt. Each SellOrder keeps its explain() method. |
The errors factory | Not exported. Construct PeerError directly with a code, message, retryable and remediation. |
Constants: BASE_CHAIN_ID, BASE_USDC_ADDRESS, USDC_DECIMALS, RATE_PRECISION, MARKET_SPREAD_BPS, ORACLE_MIN_CONVERSION_RATE_SENTINEL, CASH_ORDER_STATUSES, CASH_ORDER_POLL_INTERVAL_MS, CASH_RETAIN_ON_EMPTY, CASH_REFERRAL_ATTRIBUTION_PREFIX, CASH_BRAND_ATTRIBUTION_PREFIX | Not exported. Define the values you need, or use toSellReferralAttributionCode() and toSellBrandAttributionCode() instead of the prefixes. |
Types: CashBrand, CashDepositInput, CashPayout, CashOrderData, DeriveCashOrderOptions, ResolvedCashDeposit, PaymentMethodLike, MethodCurrencyLike, CuratorPayeeDataInput | Not exported. For a brand, use PeerOptions['brand']; for a prepared payee, use SellPayeeInput. |
Buying
createPeer() also returns peer.buy (quote, peer.buy(offer, { signer }), payment, complete, and cancel), which @zkp2p/cash never offered. In 0.16.0-rc.1, the full live purchase (signal, pay, and PeerAuth proof) has not been proven on a live network. The buy side ships on a live staging quote and unit tests, so treat it as a preview.
Checklist
- Replace the dependency and pin
@zkp2p/sdk@0.16.0-rc.1. - Replace
createCashClientwithcreatePeerand remove the dropped options. - Rename calls, errors, constants, and types with the tables above.
- Handle
PAYEE_NOT_FOUNDas a non-retryable input error. - Remove reads of
capabilities().sourceandcapabilities().destination. - Keep stored
depositIdvalues;peer.sell.order()reads Cash orders. - Repeat the staging verification before shipping.