Skip to main content

useToken() function

Warning: This API is now obsolete.

use useContract() instead

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

Example

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

export default function Component() {
const token = useToken("<YOUR-CONTRACT-ADDRESS>")

// 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 token.balance()
return balance
}

...
}

Signature:

export declare function useToken(contractAddress?: string): Token | undefined;

Parameters

ParameterTypeDescription
contractAddressstring(Optional) the address of the Token contract, found in your thirdweb dashboard

Returns:

Token | undefined