Skip to content

giveApproval

The giveApproval method approves Symphony to spend tokens on behalf of the user. This approval is necessary before executing swaps with non-native tokens.

Signature

async giveApproval(): Promise<TransactionReceipt>

Returns

Returns a Promise that resolves to the transaction receipt of the approval transaction.

Example Usage

const symphony = new Symphony();
 
// Get a route
const route = await symphony.getRoute(tokenIn, tokenOut, "1.0");
 
// Request approval
const approvalTx = await route.giveApproval();
console.log(`Approval transaction: ${approvalTx.transactionHash}`);
 
// After approval is confirmed, you can swap
const { swapReceipt } = await route.swap();

Notes

  • A wallet client must be connected to give approval
  • The method approves the exact amount needed for the swap
  • The method simulates the transaction before sending to catch potential errors
  • The method waits for transaction confirmation by default
  • No approval is needed for native token swaps
  • You can skip manual approval by using swap with skipApproval: false

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 approval transaction fails
  • The transaction simulation fails