Checking Allowance & Getting Approve TX Data
Using the SDK:
Use getTokenAllowance to check current allowance:
import { getTokenAllowance } from '@lifi/sdk';
const allowance = await getTokenAllowance(token, ownerAddress, spenderAddress);
Use setTokenAllowance to approve tokens:
import { setTokenAllowance } from '@lifi/sdk';
const txHash = await setTokenAllowance({
walletClient,
token: { address: tokenAddress, chainId },
spenderAddress: approvalAddress, // from quote.estimate.approvalAddress
amount: fromAmount,
});
Using the API directly:
The approvalAddress is returned in the quote response under estimate.approvalAddress. You'll need to call the ERC20 approve and allowance functions directly on the token contract using this address as the spender.
The End-to-end Transaction Example page (mentioned below) shows a complete checkAndSetAllowance function using ethers.js.
Want to learn more? These pages from our main website Knowledge base and its AI powered helpful assistant may help: