UNPKG

@avalanche-sdk/client

Version:

A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa

23 lines (19 loc) 671 B
import { readContract } from "viem/actions"; import { AvalancheWalletCoreClient } from "../../../clients/createAvalancheWalletCoreClient.js"; import { erc20ABI } from "../abis/erc20.js"; import { GetErc20DecimalsParameters, GetErc20DecimalsReturnType, } from "./types/getErc20Decimals.js"; export async function getErc20Decimals( client: AvalancheWalletCoreClient, params: GetErc20DecimalsParameters ): Promise<GetErc20DecimalsReturnType> { const { contractAddress, abi } = params; const decimals = await readContract(client, { abi: abi ?? erc20ABI, functionName: "decimals", address: contractAddress, }); return Number(decimals) as any; }