generateCalldata
The generateCalldata method encodes the transaction data for a swap without executing it. This is useful for transaction simulation, gas estimation, or integrating with other smart contracts.
Signature
async generateCalldata(params?: {
from?: string | WalletClient | Signer;
route?: Route;
includesNative?: boolean;
options?: {
isRaw?: boolean;
outTokenDecimals?: number;
};
slippage?: {
slippageAmount?: string | number;
isBps?: boolean;
}
}): Promise<CalldataResult>TypeScript Types
// Import for viem
import type { Route } from 'symphony-sdk/viem';
import type { CalldataResult } from 'symphony-sdk/types/viem';
import type { WalletClient } from 'viem';
// Import for ethersV5
import type { Route } from 'symphony-sdk/ethersV5';
import type { CalldataResult } from 'symphony-sdk/types/ethersV5';
import type { Signer } from 'ethers';
// Import for ethers v6
import type { Route } from 'symphony-sdk/ethers';
import type { CalldataResult } from 'symphony-sdk/types/ethers';
import type { Signer } from 'ethers';
interface CalldataResult {
from: string;
to: string;
data: `0x${string}`;
value: string;
}Parameters
from(optional): The sender's address or wallet client. Defaults to the current signer/wallet.route(optional): The route to use for the swap. Defaults to the route instance's route.includesNative(optional): Whether the swap includes native token. Defaults to the route instance's value.options(optional): Formatting options:isRaw: If true, amounts are in raw units. Defaults to true.outTokenDecimals: Output token decimals for slippage calculation.
slippage(optional): Slippage configuration:slippageAmount: Slippage tolerance. Defaults to config value.isBps: If true, slippage is in basis points (10000 = 100%). Defaults to false.
Returns
Returns a Promise that resolves to a transaction object containing:
from: The validated sender addressto: The Symphony contract addressdata: The encoded calldata for the swapvalue: Amount of native tokens (if applicable)
Example Usage
Viem
const symphony = new Symphony();
// Get a route
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Generate calldata
const tx = await route.generateCalldata({
from: "0xa43aed657D44e432121843B8784eFc3dE3Cf3Aa2",
});
// Simulate the transaction
const result = await publicClient.call(tx);
console.log(`Simulation result: ${result}`);
//Example output
{
"account": "0xa43aed657D44e432121843B8784eFc3dE3Cf3Aa2",
"to": "0x4b5e80Ff7e93B4055E3c4482F7567491E274004C",
"data": "0xdc1a.............00000000bb8",
"value": "100000000000000000"
}Notes
- The method validates the
fromaddress, whether it's provided as a string or through a wallet client. - If
fromargument is not provided, function falls back to existing wallet connected to Symphony SDK if any. - For native token swaps, the
valuefield will contain the amount of native tokens to send. - The generated calldata includes slippage protection based on the provided configuration.
- The transaction sender is labeled as
fromon Ethers V5 and Ethers V6 implementations. On Viem, transaction sender is labeled asaccountas Viem expects transaction sender address underaccountfield on followup interactions.

