Approve Amount
This method allows users to approve a specific amount of tokens (such as USDT or other tokens) to be used within the system. The approval is required for specific actions, such as adding liquidity to the pool or purchasing insurance cover for a bet.
For example, when a user adds liquidity or buys insurance cover, they need to first approve the amount of tokens they wish to use. This method ensures that the necessary amount is approved for these operations to proceed.
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 amountApprovalResponse = await kohin.approveAmount({
amount: 56.68,
walletClient: walletClient, // Refer to Pass WalletClient Instance section for appropriate usage
}); // for 56.68 USDT
console.log("Amount Approval Response:", amountApprovalResponse);
Return Value
Returns a Promise resolving to an object with the following structure:
{
success: boolean; // Indicates whether the approval was successful
error?: string; // Error message (if the call fails)
approveData?: any; // Data related to the approval transaction, if applicable
approveHash?: string; // Transaction hash for the approval, if successful
}
Error Handling
Handle potential errors gracefully by validating the response or using a try-catch block:
try {
const amountApprovalResponse = await kohin.approveAmount({
amount: 56.68,
walletClient: walletClient,
});
if (!amountApprovalResponse.success) {
console.error("Error:", amountApprovalResponse.error);
// Display the error message to the user
toastify(amountApprovalResponse.error, "error");
} else {
console.log("Approval Response:", amountApprovalResponse.transactionHash);
}
} catch (error) {
console.error("Unexpected error:", error.message);
// Display a fallback error message
toastify("Failed to approve amount. Please try again.", "error");
}
Example Response
Success Response:
{
"success": true,
"approveData": {
"blockHash": "0x8e59f1e5659326b7b05200b171153dd96c16407ce4b29c31b60eac568a0b95f6",
"blockNumber": 16647288,
"contractAddress": null,
"cumulativeGasUsed": 756062,
"effectiveGasPrice": 99680306396,
"from": "0x670eebd1efdf8d576e1fe554f3d8e905f28cc5a9",
"gasUsed": 756062,
"logs": [
/* log data */
],
"logsBloom": "0x00000000000000000080000000020000000000000000000000200800000000000000008000000000000040000000008000048000000000000000000000200000000010000000000080000008000000800000000000000000000100000000020000000000020000000000000000000800000000000000000880000010000000000000000000000000000000000000001000008800000000000000000000000000221008020000000000000000000000000000000000001000000000000000004010000022000040000001000010000000000000004000000000100000000020000011000000000000000000000800000000000000000000000000008020102000",
"status": "success",
"to": "0x34a07094a4e49a1cc745438ba5aa033f2579daae",
"transactionHash": "0xff16dc02da777d04f8a9bc40f1037910b094f92779703b03824d3dc7f51e3b56",
"transactionIndex": 0,
"type": "eip1559"
},
"approveHash": "0xff16dc02da777d04f8a9bc40f1037910b094f92779703b03824d3dc7f51e3b56"
}
Error Response:
{
"success": false,
"error": "Insufficient balance to approve amount."
}