Get paraUSD Allowance
The getParabolUSDAllowance
method allows you to check the amount of paraUSD tokens that a specific address (spender) is allowed to spend on behalf of the ParabolAccount
owner. This is crucial for operations that require token approval, such as lending.
Usage
import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
async function checkParabolUSDAllowance() {
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.ZKSYNC;
const account = await ParabolAccount.fromPrivateKey({
privateKey,
chainId,
});
const spender = "0x..."; // Address of the spender to check
try {
const allowance = await account.getParabolUSDAllowance(spender);
console.log("paraUSD allowance:", allowance.toString());
} catch (error) {
console.error("Error checking paraUSD allowance:", error);
}
}
Parameters
spender
:Address
- The address of the spender to check the allowance for.
Returns
Promise<bigint>
- A promise that resolves to the allowance amount as a bigint in wei.
Important Notes
- The allowance is returned as a bigint, representing the amount in wei (smallest unit of paraUSD).
- This method involves a read operation on the blockchain and does not modify any state.
- The allowance represents the maximum amount the spender can transfer on behalf of the ParabolAccount owner.
Error Handling
This method may throw a ParabolSDKError
if the read operation fails. Always wrap the call in a try-catch block to handle potential errors.
Use Cases
- Checking if sufficient allowance is set before performing operations that require token approval.
- Displaying the current allowance in a user interface.
- Determining if additional approval is needed before a transaction.