Skip to content

Router Swaps

The VoidAI Router enables token swaps within the same chain or across compatible networks using the routeSwap method. Like other router operations, routeSwap returns a signed transaction payload for the user’s wallet.


Always estimate fees before executing a swap to show the user the expected output and total cost.

const estimate = await sdk.bridge.getRouterSwapFeeEstimate({
originAssetId: 1, // ID of the source asset
destinationAssetId: 2, // ID of the destination asset
amount: 100,
operationType: 'SWAP',
toAddress: '0xRecipient...',
});
console.log(`Estimated Output: ${estimate.swapAmount}`);
console.log(`Total Fee: ${estimate.totalFee}`);
console.log(`Platform Fee: ${estimate.platformFee}`);
console.log(`Tenant Fee: ${estimate.tenantFee}`);
PropertyTypeDescription
swapAmountstringEstimated output amount the recipient will receive.
totalFeestringTotal combined fee.
platformFeestringVoidAI platform fee component.
ccipFeestringCCIP fee component (typically 0 for pure swaps).
tenantFeestringFee collected by the tenant/integrator.

  1. Call routeSwap to receive the transaction payload.
  2. Sign and send the transaction using your wallet provider.
// Step 1 — Request swap payload
const response = await sdk.bridge.routeSwap({
operationType: 'SWAP',
originAssetId: 1, // Source asset ID
destinationAssetId: 2, // Destination asset ID
fromAddress: '0xSender...',
toAddress: '0xRecipient...',
amount: 100,
});
// Step 2 — Send transaction via wallet provider
if (response.success && response.data) {
const { to, data, value, chainId } = response.data;
await window.ethereum.request({
method: 'eth_sendTransaction',
params: [
{
from: '0xSender...',
to,
data,
value,
chainId: `0x${chainId.toString(16)}`, // chainId as hex
},
],
});
}
PropertyTypeRequiredDescription
operationType'SWAP'Must be the literal string 'SWAP'.
originAssetIdnumberID of the source asset.
destinationAssetIdnumberID of the destination asset.
fromAddressstringSender wallet address.
toAddressstringRecipient wallet address.
amountnumberAmount to swap.
PropertyTypeDescription
successbooleanWhether the routing request was successful.
identifierstringUnique transaction identifier for tracking.
data.tostringRouter contract address.
data.datastringEncoded calldata for the swap.
data.valuestringNative token value to send with the transaction.
data.chainIdnumberChain ID of the source network.

If a swap has not yet been finalized on-chain, it can be cancelled:

const result = await sdk.bridge.cancelRouterSwap({
uuid: 'transaction-uuid',
});
console.log('Cancelled:', result.success);