List available routes
Swing searches across all available routes across blockchains, contracts and DEXes before initiating a token transfer.
Depending on the contract, your quote may include one or two types of routes:
deposit
: native staking route
swap
: DEX aggregator route
Use the instructions below to request all possible routes from our API.
If you haven't already, make sure you have connected a wallet .
To get a quote, you'll need to provide the source chain and the destination contract. You can use the SDK's staking contract methods to help.
import type { TransferParams } from '@swing.xyz/sdk' ;
// Get all available destination chains with a staking contract
const stakingChains = swingSDK. getAvailableStakingChains ({
fromChainSlug: 'ethereum' ,
});
// Choose a staking chain then get all available contracts
const contracts = swingSDK. getContractsForChain ({
chainSlug: stakingChains[ 0 ],
});
// Choose the contract you want to deposit into
const contract = contracts[ 0 ];
// Deposit USDC on ethereum to a staking contract
const transferParams : TransferParams = {
fromUserAddress: '0x0000' , // Source chain wallet address
toUserAddress: '0x0000' , // Destination wallet address
fromChain: 'ethereum' , // Source chain
fromToken: 'USDC' , // Source token
amount: '100' , // Amount to transfer in token decimals
// Provide the chain, token and ID from the chosen contract
toChain: contract.chain,
toToken: contract.inputToken.symbol,
contractId: contract.id,
};
CopyCopied!
Get a quote for each available route for the transfer.
const quote = await swingSDK. getQuote (transferParams);
CopyCopied!
The best route will always be listed first, but feel free to choose any available bridge or exchange. You use this route in the next step, execute a staking .
const transferRoute = quote.routes[ 0 ];
CopyCopied!