Route
Last updated
;(async () => {
const payload = {
integratorId: "xxx",
fromChain: "8453",
toChain: "1",
fromToken: "0x8fe815417913a93ea99049fc0718ee1647a2a07c",
toToken: "0x8fe815417913a93ea99049fc0718ee1647a2a07c",
fromAmount: "100000000000000000",
fromAddress: "0x123...abc",
toAddress: "0x123...abc",
paymentToken: "0x0000000000000000000000000000000000000000",
slippage: 1.5,
expressDelivery: false,
};
const encoded = encodeURIComponent(JSON.stringify(payload));
const url = `https://xswap.link/api/route/v1?data=${encoded}`;
const res = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
}
const route = await res.json();
console.log("Generated route:", route);
})();{
"estAmountOut": "100000000000000000",
"minAmountOut": "100000000000000000",
"transactions": {
"swap": {
"to": "...",
"data": "...",
"value": "..."
}
},
"xSwapFees": {
"ccipFee": "1929371550307947",
"xSwapFee": {
"tokenFee": "0",
"nativeFee": "246913580246913"
},
"expressDeliveryFee": "0"
}
}