swap()

swap()

Gasless DEX swap through any Uniswap V2-compatible router on Flare. Encode the calldata with ethers.js, you keep full control over routing, slippage, and deadlines.

Usage

typescript
import { Zedkr } from "zedkr";
const client   = await Zedkr.create({ provider });
const callData = iface.encodeFunctionData("swapExactTokensForTokens", [amountIn, amountOutMin, [FXRP, USDT], to, deadline]);
const result   = await client.swap(signer, BLAZESWAP_ROUTER, callData);
console.log(result.txHash);

Full example - FXRP to USDT via BlazeSwap

typescript
import { ethers } from "ethers";

const BLAZESWAP = "0x2b8f51c1Ffadb778D48A5bd6d0169Cf648568243";
const FXRP      = "0x0b6A3645c240605887a5532109323A3E12273dc7";
const USDT      = "0xC1A5B41512496B80903D1f32d6dEa3a73212E71F";

const iface    = new ethers.Interface(["function swapExactTokensForTokens(uint256,uint256,address[],address,uint256) returns (uint256[])"]);
const amountIn = ethers.parseUnits("10", 6); // 10 FXRP
const deadline = Math.floor(Date.now() / 1000) + 300;
const callData = iface.encodeFunctionData("swapExactTokensForTokens", [amountIn, 0n, [FXRP, USDT], await signer.getAddress(), deadline]);

const result   = await client.swap(signer, BLAZESWAP, callData);
Warning
Approve the router (not the DEX) for the input token before swapping.
Tip
BlazeSwap on Coston2: 0x2b8f51c1Ffadb778D48A5bd6d0169Cf648568243