useTokenSupply
Hook for getting the current token supply of a smart contract.
Available to use on smart contracts that implement the ERC20 standard.
import { useTokenSupply } from "@thirdweb-dev/react";
Usage
Provide your token contract as the argument.
import { useTokenSupply } from "@thirdweb-dev/react";
// Your smart contract address
const contractAddress = "{{contract_address}}";
function App() {
const { data, isLoading, error } = useTokenSupply(contractAddress);
if (error) {
console.error("failed to get token supply", error);
}
return (
<div>
{isLoading ? (
<p>Loading token supply...</p>
) : (
<p>
Token Supply: {data?.displayValue} {data?.symbol}
</p>
)}
</div>
);
}
The returned data is an object that contains the following information:
symbol- The token symbolvalue- The token supply inBigNumberformatname- The token namedecimals- The token decimalsdisplayValue- The token supply in human readable format
Return value
The hook returns an object with the following properties:
data- The token supply informationisLoading- A boolean value indicating if the data is still loadingerror- An error object in case the call fails