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(): Promise<boolean>
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}`);
}
// Now we can swap
const { swapReceipt } = await route.swap();
Notes
- If the input token is the native token (e.g., SEI),
checkApproval
will always returntrue
since 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
swap
method withskipApproval: false
. Seeswap
for 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