Fetching Decimal Precision
The getDecimalPrecise
method retrieves the decimal precision used for the token. This is important for ensuring correct handling of token amounts and calculations, especially when tokens have different decimal places.
Usage
import kohin from "./kohinInstance";
const decimalsResponse = await kohin.getDecimalPrecise();
if (decimalsResponse.success) {
console.log("Token Decimal Precision:", decimalsResponse.decimalPrecise);
} else {
console.error("Error fetching decimal precision:", decimalsResponse.error);
}
Return Value
The getDecimalPrecise
method returns an object with the following structure:
{
success: boolean; // Indicates if the operation was successful
error?: string; // Error message if the operation failed
decimalPrecise?: number; // The decimal precision of the token (optional)
}
Error Handling
Here's how you can handle errors while fetching decimal precision:
try {
const res = await kohin.getDecimalPrecise();
if (res.success) {
console.log("Token Decimal Precision:", res.decimalPrecise);
} else {
console.error("Error fetching decimal precision:", res.error);
}
} catch (error: any) {
console.error("Unexpected error while fetching decimal precision:", error);
}
Example Response
Success Response:
{
"success": true,
"decimalPrecise": 6
}
Error Response:
{
"success": false,
"error": "Unable to fetch decimal precision for the token."
}