useToken

Hook for getting an instance of a Token contract. This contract supports ERC20 compliant tokens.

function useToken(
  contractAddress: RequiredParam<string>,
): undefined | Token;

Parameters


Returns

type ReturnType = undefined | Token;

Example

import { useContract } from '@thirdweb-dev/react'

export default function Component() {
  const { contract } = useContract("<YOUR-CONTRACT-ADDRESS>", "token")

  // Now you can use the token contract in the rest of the component

  // For example, this function will get the connected wallets token balance
  async function balance() {
    const balance = await contract.balance()
    return balance
  }

  ...
}