Skip to main content

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
CashErrorPeerError
isCashErrorisPeerError
CashErrorCodePeerErrorCode
CashErrorShapePeerErrorShape
CashErrorRecoveryPeerErrorRecovery
isUserRejectedErrorisUserRejectedError
CASH_ATTRIBUTION_CODESELL_ATTRIBUTION_CODE (still "peer-cash")
toCashReferralAttributionCodetoSellReferralAttributionCode
toCashBrandAttributionCodetoSellBrandAttributionCode
MIN_CASHOUT_AMOUNTMIN_SELL_AMOUNT
RECOMMENDED_MIN_CASHOUT_AMOUNTRECOMMENDED_MIN_SELL_AMOUNT
usdc, formatUsdcusdc, 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
CashClientPeerSell (or Peer["sell"])
CashoutInputSellInput
CashoutResultSellResult
PrepareResultSellPrepareResult
PreparedCashoutReceiptPreparedSellReceipt
CashPreparedStepSellPreparedStep
CashOrderSellOrder
CashOrderStateSellOrderState
CashFillSellFill
CashCapabilitiesSellCapabilities
CashPlatformCapabilitySellPlatformCapability
CashEstimateSellEstimate
EstimateInputSellEstimateInput
EstimateOptionsSellEstimateOptions
CashFillStatsSellFillStats
CashFillEtaSellFillEta
CashLegSellLeg
CashMultiCurrencyLegSellMultiCurrencyLeg
CashReceiveLegSellReceiveLeg
CashPayeeInputSellPayeeInput
CashBuyerProfileSellBuyerProfile
WithdrawResultSellWithdrawResult
WithdrawOptionsSellWithdrawOptions
TopUpResultSellTopUpResult
WatchOptionsSellWatchOptions
OrdersOptionsSellOrdersOptions
SignerOptionsSignerOptions

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: truePAYEE_NOT_FOUND, retryable: false
capabilities()Includes source and destinationNo 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 textWorded 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 featureWith @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 methodsUse registerPayeeDetails(), openVenmoGmailConnect() or getVenmoGmailConnectUrl(), openXMoneyConnect() or getXMoneyConnectUrl(), and getSellerCredentialStatus(). See Optional receipt linking.
Cash App and PayPal App Clip account connection: prepareSarConnect and related methodsNot available.
Codecs: zod schemas and *ToJson / *FromJson, such as orderToJson and prepareResultToJsonNot available. Use a bigint-safe JSON.stringify replacer; see Serialize across process boundaries.
React hooks from @zkp2p/cash/reactNot available. Call peer.sell methods from your own hooks.
Agent tool manifest from @zkp2p/cash/toolsNot 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, rateToNumberNot 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 factoryNot 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_PREFIXNot exported. Define the values you need, or use toSellReferralAttributionCode() and toSellBrandAttributionCode() instead of the prefixes.
Types: CashBrand, CashDepositInput, CashPayout, CashOrderData, DeriveCashOrderOptions, ResolvedCashDeposit, PaymentMethodLike, MethodCurrencyLike, CuratorPayeeDataInputNot 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​

  1. Replace the dependency and pin @zkp2p/sdk@0.16.0-rc.1.
  2. Replace createCashClient with createPeer and remove the dropped options.
  3. Rename calls, errors, constants, and types with the tables above.
  4. Handle PAYEE_NOT_FOUND as a non-retryable input error.
  5. Remove reads of capabilities().source and capabilities().destination.
  6. Keep stored depositId values; peer.sell.order() reads Cash orders.
  7. Repeat the staging verification before shipping.