Fetching Balance of a Deposit
The getBalanceOfDeposit
method retrieves the balance associated with a specific deposit by querying the smart contract. It helps you track the available funds in the deposit for future use or withdrawal.
Usage
import kohin from "./kohinInstance";
const depositBalance = await kohin.getBalanceOfDeposit({
depositId: 1099511627894,
});
if (depositBalance.success) {
console.log("Deposit Balance:", depositBalance.nodeWithdrawView);
} else {
console.error("Error fetching deposit balance:", depositBalance.error);
}
Return Value
The getBalanceOfDeposit
method returns an object with the following structure:
{
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
nodeWithdrawView?: number; // The balance available for withdrawal in the deposit
}
Error Handling
Here's how you can handle errors while fetching the deposit balance:
try {
const res = await kohin.getBalanceOfDeposit({ depositId: 1099511627894 });
if (res.success) {
console.log("Deposit Balance:", res.nodeWithdrawView);
} else {
console.error("Error fetching deposit balance:", res.error);
}
} catch (error: any) {
console.error("Unexpected error while fetching deposit balance:", error);
}
Example Response
Success Response:
{
"success": true,
"nodeWithdrawView": 1000
}
Error Response:
{
"success": false,
"error": "Unable to fetch deposit balance."
}