Repository navigation
v0.3.0
Overview
New SDK surface:
userIponquotes.get()andswaps.create()destinationMemoonquotes.get()andswaps.create()QuoteRoute.destinationMemoLabelDESTINATION_MEMO_UNSUPPORTEDproviderStatusonTransactionWebhookData.input
SDK 0.3.0 requires Pegaroute v0.9.0 for destination memo and webhook provider-status fields.
Upgrade guide: 0.2.0 → 0.3.0
Install the new SDK:
npm install @pegaroute/sdk@0.3.00.3.0 is additive over 0.2.0. Existing quote and swap calls remain valid. No catalog-specific SDK changes are required: chain and token IDs are already typed as strings.
To enable SwapSpace routes:
- Send the same
userIpto bothquotes.get()andswaps.create().
const quote = await pr.quotes.get({
fromChain: "ETH",
fromToken: "ETH",
toChain: "CANTON",
toToken: "CC",
amount: "1",
userIp: "203.0.113.7",
});
const route = quote.routes.find((candidate) => candidate.provider === "swapspace") ?? quote.routes[0];
const swap = await pr.swaps.create({
fromChain: "ETH",
fromToken: "ETH",
toChain: "CANTON",
toToken: "CC",
amount: "1",
senderAddress: "0x1111111111111111111111111111111111111111",
destinationAddress: "canton-address",
userIp: "203.0.113.7",
quoteId: quote.quoteId,
routeProvider: route?.provider,
});- To send a destination memo, tag, or payment ID, pass
destinationMemoto both calls.
const destinationMemo = "payment-id-1";
const quote = await pr.quotes.get({
fromChain: "ETH",
fromToken: "ETH",
toChain: "CANTON",
toToken: "CC",
amount: "1",
userIp: "203.0.113.7",
destinationMemo,
});
const destinationMemoLabel = quote.routes[0]?.destinationMemoLabel;
const swap = await pr.swaps.create({
fromChain: "ETH",
fromToken: "ETH",
toChain: "CANTON",
toToken: "CC",
amount: "1",
senderAddress: "0x1111111111111111111111111111111111111111",
destinationAddress: "canton-address",
userIp: "203.0.113.7",
destinationMemo,
quoteId: quote.quoteId,
routeProvider: quote.routes[0]?.provider,
});Use destinationMemoLabel for the field label. It is the live provider label, such as Memo, Tag, or Payment ID. Do not add destinationMemo to execution.memo; it is not a source-chain signing memo.
- Handle the new errors.
import { PegarouteError } from "@pegaroute/sdk";
try {
const quote = await pr.quotes.get(params);
} catch (error) {
if (error instanceof PegarouteError) {
if (error.code === "USER_IP_REQUIRED") {
// Collect a valid end-user IP and retry the quote.
}
if (error.code === "DESTINATION_MEMO_UNSUPPORTED") {
// Remove destinationMemo or choose a route that supports it.
}
}
}- Read provider status evidence from webhooks when present.
if (event.data.input.providerStatus?.actionRequired) {
showAction(event.data.input.providerStatus.message);
}