Swap
Integrating Swap to website
Steps to Integration
0. Prepare Input
token1_address: address, // if it is $IP native token, use WIP_ADDRESS
token2_address: address, // if it is $IP native token, use WIP_ADDRESS
amount1: bigint, // amount of token 1 you want to give
amount2Min: bigint, // minimal number of token 2 you want to receive
expire_time: bigint// expiration timestamp for a swap
signer: ethers.Signer. //1. Finding the best swap path
const res = await fetch(`https://piperxdb.piperxprotocol.workers.dev/api/swap/swapExactToken?tokenIn=${tokenIn}&tokenOut=${tokenOut}&amount=${amount}&type=exactInput&isAggregator=true`);
const { universalRoutes, num } = await res.json();2. Approve tokens
3. conduct swap
Last updated