useTokenDecimals
Hook for retrieving the decimals of a token from its smart contract.
import { useTokenDecimals } from "@thirdweb-dev/react";
Usage
Provide the token contract instance as the argument.
import { useTokenDecimals, useContract } from "@thirdweb-dev/react";
// Your token contract address
const contractAddress = "{{contract_address}}";
function App() {
const { contract } = useContract(contractAddress);
const { data: decimals, isLoading, error } = useTokenDecimals(contract);
if (error) {
console.error("failed to fetch decimals", error);
}
return <div>Decimals: {isLoading ? "Loading..." : decimals}</div>;
}
Configuration
No configuration is needed.