Before you start using sweep swap API, make sure you understand the content of the swap API. Normally, you only need to use a transaction body different from the swap API in the last step to build. Check below OpenOcean swap API as reference. It currently applies to V3 version.
Here is the last step! Now you have several ways to swap the token you selected. You can use the multi_swap_quote API to get the transaction body from our API server. Here is a case for you to make a transaction on Arbitrum Chain.
The work flow we recommend for API users, is using swap_quote API to get transaction body, then use the wallet to request your transaction on chain.
async swap() {
let params = {
inToken: [
{
inTokenSymbol: "ETH",
inTokenAddress: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
amount: "1000000000000000000",
slippage: 100
},
{
inTokenSymbol: "ARB",
inTokenAddress: "0x912CE59144191C1204E64559FE8253a0e49E6548",
amount: "1000000000000000000",
slippage: 100
}
],
outToken: {
outTokenSymbol: "USDT",
outTokenAddress: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"
},
gasPrice: 10000000,
account: "0xB3cbefF0336BaA4863Cb51238bD6C35BDAaB3D84"
};
const res = await axios.post("https://open-api.openocean.finance/v3/arbitrum/multi_swap_quote", params);
if(res) {
const {data,gasPrice} = res.data;
const swapParams = {
from:this.address,
to:'0x6352a56caadc4f1e25cd6c75970fa768a3304e64', //Please use the contract from the contract page
gasPrice: gasPrice,
data
};
const result = await this.myWallet.sdk.eth.sendTransaction(swapParams)
};
Once your wallet plugin was triggered, which means you are successfully using the sendTransaction function and all params are set. You can swap your token and the transaction hash can be fetched once your transaction is sent on-chain.