Skip to main content

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 symbol
  • value - The token supply in BigNumber format
  • name - The token name
  • decimals - The token decimals
  • displayValue - The token supply in human readable format

Return value

The hook returns an object with the following properties:

  • data - The token supply information
  • isLoading - A boolean value indicating if the data is still loading
  • error - An error object in case the call fails