Suave Aggregator
- Overview
- SDK Guide
- API Reference
Suave Checkout
- Introduction
- Use Cases
- API Documentation
- SDK Documentation
- Overview
- Getting started
- Functionality
- React
Routing
Get routes
Suave SDK makes it easy to get and execute cross-chain swap routes.
Features
- Cross-Chain Swaps: Execute swaps across different blockchain networks.
- Quotes: Routes includes quotes for each step of the route.
- Customizable: Adjust for different preferences, speed, price, etc.
Usage Example
import { SuaveSDK } from 'suave-sdk';
const sdk = new SuaveSDK({
apiKey: 'your-api-key'
});
//Custom options for the route
const options = {
preference:'price',
feePercent: 0.01,
feeChainId:1,
feeTokenAddress:'0xa23202318e7eAf7179A845068aC64CE332Ea66B'
}
const slippagePercent = 0.5;
// Get the best routes to execute a swap
const routes = sdk.getRoutes(tokenA,chainA,amount, tokenB,chainB,slippagePercent,options).then(routes => {
console.log('Best Routes:', routes);
});
// Get the cheapest route to execute a swap
const route = sdk.getCheapestRoute(tokenA,chainA,amount, tokenB,chainB,slippagePercent,options).then(route => {
console.log('Cheapest route:', route);
});
// Get the fastest route to execute a swap
const route = sdk.getFastestRoute(tokenA,chainA,amount,tokenB,chainB,slippagePercent,options).then(route => {
console.log('Fastest route:', route);
});
//The route object is complex but does not need to used directly, instead it should be sent to the execution method.
Example Route object
The route return object is a complex structure that contains the route details, quotes for each step, and the transactions required to execute the route.
{
id: 'eae098cd-63e4-4879-a673-ac80d53f41ec',
fromChainId: 42161,
fromAmountUSD: '10.0030',
fromAmount: '10000000',
fromToken: {
address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
chainId: 42161,
symbol: 'USDC',
decimals: 6,
name: 'USD Coin',
priceUSD: '1.000300090027008'
},
toChainId: 10,
toAmountUSD: '9.4292',
toAmount: '9429234882404367417',
toAmountMin: '9382088707992345580',
toToken: {
address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
chainId: 10,
symbol: 'DAI',
decimals: 18,
name: 'DAI Stablecoin',
coinKey: 'DAI',
logoURI: 'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeAC495271d0F/logo.png',
priceUSD: '1'
},
gasCostUSD: '0.0087',
containsSwitchChain: true,
steps: [ {
"protocol": "Matcha",
"fromToken": "0x514910771AF9Ca656af840dff83E8264EcF986CA",
"symbol": "LINK",
"decimals": 18,
"name": "Chainlink",
"toToken": {
"chain_to_address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"decimals": 18,
"name": "Dai",
"logoURI": "https://tokens.1inch.io/0x6b175474e89094c44da98b954eedeac495271d0f.png"
},
"fromChainId": 1,
"toChainId": 1,
"inputAmount": "1000000000000000000",
"outputAmount": "25153126674823844322",
"estimatedTime": "3",
"fees": [
{
"amount": "37786364787463238",
"currency": {
"chain_to_address": {
"1": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"10": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
"137": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
"42161": "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1"
},
"symbol": "DAI",
"decimals": 18,
"chains": [
{
"id": 1,
"name": "Ethereum",
"nativeCurrency": {
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"rpcUrls": {
"default": {
"http": [
"https://eth.merkle.io"
]
}
},
"blockExplorers": {
"default": {
"name": "Etherscan",
"url": "https://etherscan.io",
"apiUrl": "https://api.etherscan.io/api"
}
},
"contracts": {
"ensRegistry": {
"address": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"
},
"ensUniversalResolver": {
"address": "0xce01f8eee7E479C928F8919abD53E553a36CeF67",
"blockCreated": 19258213
},
"multicall3": {
"address": "0xca11bde05977b3631167028862be2a173976ca11",
"blockCreated": 14353601
}
}
},
{
"id": 137,
"name": "Polygon",
"nativeCurrency": {
"name": "POL",
"symbol": "POL",
"decimals": 18
},
"rpcUrls": {
"default": {
"http": [
"https://polygon-rpc.com"
]
}
},
"blockExplorers": {
"default": {
"name": "PolygonScan",
"url": "https://polygonscan.com",
"apiUrl": "https://api.polygonscan.com/api"
}
},
"contracts": {
"multicall3": {
"address": "0xca11bde05977b3631167028862be2a173976ca11",
"blockCreated": 25770160
}
}
},
{
"formatters": {
"block": {
"type": "block"
},
"transaction": {
"type": "transaction"
},
"transactionReceipt": {
"type": "transactionReceipt"
}
},
"serializers": {},
"contracts": {
"gasPriceOracle": {
"address": "0x420000000000000000000000000000000000000F"
},
"l1Block": {
"address": "0x4200000000000000000000000000000000000015"
},
"l2CrossDomainMessenger": {
"address": "0x4200000000000000000000000000000000000007"
},
"l2Erc721Bridge": {
"address": "0x4200000000000000000000000000000000000014"
},
"l2StandardBridge": {
"address": "0x4200000000000000000000000000000000000010"
},
"l2ToL1MessagePasser": {
"address": "0x4200000000000000000000000000000000000016"
},
"disputeGameFactory": {
"1": {
"address": "0xe5965Ab5962eDc7477C8520243A95517CD252fA9"
}
},
"l2OutputOracle": {
"1": {
"address": "0xdfe97868233d1aa22e815a266982f2cf17685a27"
}
},
"multicall3": {
"address": "0xca11bde05977b3631167028862be2a173976ca11",
"blockCreated": 4286263
},
"portal": {
"1": {
"address": "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"
}
},
"l1StandardBridge": {
"1": {
"address": "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1"
}
}
},
"id": 10,
"name": "OP Mainnet",
"nativeCurrency": {
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"rpcUrls": {
"default": {
"http": [
"https://mainnet.optimism.io"
]
}
},
"blockExplorers": {
"default": {
"name": "Optimism Explorer",
"url": "https://optimistic.etherscan.io",
"apiUrl": "https://api-optimistic.etherscan.io/api"
}
},
"sourceId": 1
},
{
"id": 42161,
"name": "Arbitrum One",
"nativeCurrency": {
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"rpcUrls": {
"default": {
"http": [
"https://arb1.arbitrum.io/rpc"
]
}
},
"blockExplorers": {
"default": {
"name": "Arbiscan",
"url": "https://arbiscan.io",
"apiUrl": "https://api.arbiscan.io/api"
}
},
"contracts": {
"multicall3": {
"address": "0xca11bde05977b3631167028862be2a173976ca11",
"blockCreated": 7654707
}
}
}
],
"name": "Dai",
"logoURI": "https://tokens.1inch.io/0x6b175474e89094c44da98b954eedeac495271d0f.png"
}
}
]
} ],
tags: []
}
On this page