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.
import { useTokenDecimals } from "@thirdweb-dev/react";
Usage
Provide your token contract as the argument.
import { useTokenDecimals, useContract } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress, "token");
const { data, isLoading, error } = useTokenDecimals(contract);
}
Return Value
The hook's data
property, once loaded, contains the decimals of the ERC20 token.
number;