Execute a Transfer
Once you have selected a transfer route, you can start the cross-chain transfer.
If you don't already have a transfer route, follow these steps .
Use the same transfer parameters you used when finding a route. This will handle the entire transfer process for you, including prompting the wallet for any required actions.
await swingSDK. transfer (transferRoute, transferParams);
CopyCopied!
Use these events to update your UI with helpful information for your users.
swingSDK. on ( 'TRANSFER' , ( transferStep , transferResults ) => {
switch (transferStep.status) {
case 'PENDING' :
// Let the user know the step is pending: `transferStep.step`
break ;
case 'WALLET_CONNECTION_REQUIRED' :
// Handle connecting wallets using your favorite library like Wagmi
// or alert the user to do it manually.
// Example: await connectWallet(transferStep.chain);
break ;
case 'CHAIN_SWITCH_REQUIRED' :
// Handle switching chains using your favorite library like Wagmi
// or alert the user to do it manually
// Example: await switchNetwork(transferStep.chain.chainId);
break ;
case 'ACTION_REQUIRED' :
// Let the user know they need to take action within their wallet, such as signing a transaction
break ;
case 'CONFIRMING' :
// Let the user know the transaction is waiting for confirmations
break ;
case 'SUCCESS' :
// The transaction was successful, yay!
break ;
case 'FAILED' :
// Alert the user there was an error. Check the message in `transferStep.error`
break ;
}
});
CopyCopied!
You may want to cancel a transfer if the user rejects a wallet connection or network switch. To do so, call cancelTransfer
with the transfer ID.
swingSDK. on ( 'TRANSFER' , async ( transferStep , transferResults ) => {
// Unique ID for the transfer in progress
const transferId = transferResults.transferId;
switch (transferStep.status) {
case 'WALLET_CONNECTION_REQUIRED' :
try {
await connectWallet (transferStep.chain);
} catch (error) {
// Cancel transfer if user rejects wallet connection
swingSDK. cancelTransfer (transferId);
}
break ;
case 'CHAIN_SWITCH_REQUIRED' :
try {
await switchNetwork (transferStep.chain.chainId);
} catch (error) {
// Cancel transfer if user rejects network switch
swingSDK. cancelTransfer (transferId);
}
break ;
}
});
CopyCopied!