checkApproval
The checkApproval method checks if Symphony has sufficient allowance to spend tokens on behalf of the user. This check is necessary before executing swaps with non-native tokens.
Signature
async checkApproval(params?: {
variable?: Route | string;
signer?: Signer; // ethers/ethersV5
walletClient?: WalletClient; // viem
amount?: string | bigint;
includesNative?: boolean;
options?: {
isRaw?: boolean;
}
}): Promise<boolean>TypeScript Types
// Import for viem
import type { Route } from "symphony-sdk/viem";
// Import for ethersV5
import type { Route } from "symphony-sdk/ethersV5";
// Import for ethers v6
import type { Route } from "symphony-sdk/ethers";Parameters
variable: Route object or token address (defaults tothis.route)signer/walletClient: Transaction signer (defaults to Route's signer)amount: Amount to check approval for (defaults to route's input amount)- If
isRaw=true: Amount in wei units - If
isRaw=false: Amount in formatted units
- If
includesNative: Whether the swap includes native token (defaults to route's value)options: Configuration optionsisRaw: If true, amount is in wei units (default:true)
Returns
Returns a Promise that resolves to:
true: Symphony has sufficient allowance to execute the swapfalse: Symphony needs approval to execute the swap
Example Usage
Viem
const symphony = new Symphony();
// Get a route
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Check if approval is needed
const isApproved = await route.checkApproval();
if (!isApproved) {
// Request approval if needed
const approvalTx = await route.giveApproval();
console.log(`Approval transaction: ${approvalTx.transactionHash}`);
}
// Now we can swap
const { swapReceipt } = await route.swap();TypeScript Example
import { Route } from "symphony-sdk/ethers";
import type { Route } from "symphony-sdk/ethers";
const route: Route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
// Check approval with type safety
const isApproved: boolean = await route.checkApproval();
if (!isApproved) {
const receipt = await route.giveApproval();
console.log(`Approved at block ${receipt.blockNumber}`);
}Custom Amount Check
// Check if a specific amount is approved
const hasEnoughAllowance = await route.checkApproval({
amount: "100.0",
options: { isRaw: false },
});
if (!hasEnoughAllowance) {
// Approve the larger amount
await route.giveApproval({
amount: "100.0",
options: { isRaw: false },
});
}Notes
- If the input token is the native token (e.g., SEI),
checkApprovalwill always returntruesince native tokens don't require approval - The method checks if the allowance is sufficient for the specific amount in the route
- A wallet client must be connected to check approval
- You can combine approval and swap in a single call using the
swapmethod withskipApproval: false. Seeswapfor details.
Error Handling
The method will throw an error if:
- No wallet client is connected
- The token address is invalid
- The token is not listed on Symphony
- The allowance check fails due to RPC issues

