Fetching Approval Amount
The getApprovalAmount
method fetches the current approval amount of tokens that the user has allowed for a particular contract (such as the insurance pool). This is useful for checking how much a user has approved for spending on the token contract.
Before proceeding, users need to follow these steps:
- Pass WalletClient instance: Refer to the
Pass WalletClient Instance
for selecting the appropriatewalletClient
instance based on authentication.
Usage
import kohin from "./kohinInstance";
const approvalAmount = await kohin.getApprovalAmount({
walletClient: walletClient, // Refer to Pass WalletClient Instance section for appropriate usage
});
if (approvalAmount.success) {
console.log("Approval Amount:", approvalAmount.allowance);
} else {
console.error("Error fetching approval amount:", approvalAmount.error);
}
Return Value
The getApprovalAmount
method returns an object with the following structure:
{
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
allowance?: number; // The amount of tokens approved for the contract
}
Error Handling
Here's how you can handle errors while fetching the approval amount:
try {
const res = await kohin.getApprovalAmount();
if (res.success) {
console.log("Approval Amount:", res.allowance);
} else {
console.error("Error fetching approval amount:", res.error);
}
} catch (error: any) {
console.error("Unexpected error while fetching approval amount:", error);
}
Example Response
Success Response:
{
"success": true,
"allowance": 5000
}
Error Response:
{
"success": false,
"error": "Unable to fetch approval amount."
}