useTokenDecimals

Hook for fetching the decimals of an ERC20 token.

Tokens usually opt for a value of 18 , imitating the relationship between Ether and Wei. Therefore, 18 is the default value returned by this function, unless your ERC20 contract explicitly overrides it.

Example

import { useTokenDecimals, useContract } from "@thirdweb-dev/react";
function App() {
const { contract } = useContract(contractAddress, "token");
const { data, isLoading, error } = useTokenDecimals(contract);
}
function useTokenDecimals(
contract: RequiredParam<TokenContract>,
): UseQueryResult<number, unknown>;

Parameters

Instance of a TokenContract

Type

let contract: RequiredParam<TokenContract>;

Returns

let returnType: UseQueryResult<number, unknown>;

The hook's data property, once loaded, contains the number that represents the number of decimals of the ERC20 token.