Transaction Building

Convert discovered routes into executable transactions ready for wallet signing

Overview

Transaction building converts discovered routes into executable blockchain transactions. The SDK handles multi-step routes, approval requirements, and gas estimation to provide transactions ready for wallet signing.

Basic Transaction Building

Building Executable Transactions

Convert discovered routes into unsigned transactions ready for wallet signing with proper gas estimates and call data.

import { AggLayerSDK } from '@agglayer/sdk';

const sdk = new AggLayerSDK();
const core = sdk.getCore();

// Step 1: Discover routes
const routes = await core.getRoutes({
  fromChainId: 1,
  toChainId: 747474,
  fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
  toTokenAddress: '0x203a662b0bd271a6ed5a60edfbd04bfce608fd36', // USDC on Katana
  amount: '1000000000',
  fromAddress: '0xUserAddress',
  slippage: 0.5,
});

// Step 2: Build transaction from best route
const selectedRoute = routes[0];
const unsignedTx = await core.getUnsignedTransaction(selectedRoute);

Approval Requirements

Checking for Required Approvals

Determine if the route requires token approval before executing the bridge transaction by checking route steps.

// Check if route requires token approval
const approvalStep = selectedRoute.steps.find(step => step.estimate.approvalAddress);

if (approvalStep) {
  console.log('Approval required before bridge transaction');
}

Claim Transaction Building

Building Claim Transactions

For Agglayer Bridge, build claim transactions to retrieve bridged assets on the destination network after AggKit processing.

if (route.provider.includes('agglayer')) {
  const claimTx = await core.getClaimUnsignedTransaction({
    sourceNetworkId: 0, // Ethereum network ID
    depositCount: 12345, // From bridge transaction
  });
}

Working Example

import { AggLayerSDK } from '@agglayer/sdk';

const sdk = new AggLayerSDK();
const core = sdk.getCore();

const routes = await core.getRoutes({
  fromChainId: 1,
  toChainId: 747474,
  fromTokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC on Ethereum
  toTokenAddress: '0x203a662b0bd271a6ed5a60edfbd04bfce608fd36', // USDC on Katana
  amount: '1000000000',
  fromAddress: '0xUserAddress',
  slippage: 0.5,
});

const selectedRoute = routes[0];
const unsignedTx = await core.getUnsignedTransaction(selectedRoute);
Edit on GitHub

Last updated on