Skip to main content

useERC20Metadata

Use this hook to retrieve metadata (name, symbol, and decimals) of a specified ERC20 token.

const { data, isLoading, error, getERC20Metadata } = useERC20Metadata({
token: "0x...",
});

Usage

import { useERC20Metadata } from "~~/hooks/eth-mobile";

function TokenInfo() {
const { data, isLoading, error, getERC20Metadata } = useERC20Metadata({
token: "0xA0b86a33E6441b8c4C327D7d0c65Bfa0ECf0e651", // USDC
});

if (isLoading) return <Text>Loading token info...</Text>;
if (error) return <Text>Error: {error}</Text>;
if (!data) return <Text>No token data available</Text>;

return (
<View>
<Text>Token Name: {data.name}</Text>
<Text>Symbol: {data.symbol}</Text>
<Text>Decimals: {data.decimals}</Text>
<Button onPress={() => getERC20Metadata()} title="Refresh Metadata" />
</View>
);
}

Configuration

ParameterTypeRequiredDescription
tokenAddressNoThe ERC20 token contract address.

Return Values

PropertyTypeDescription
dataERC20Metadata | nullThe token metadata containing name, symbol, and decimals.
isLoadingbooleanWhether the metadata is currently being fetched.
errorstring | nullAny error message that occurred during metadata fetching.
getERC20Metadata(token?: Address) => Promise<ERC20Metadata | undefined>Function to manually fetch metadata for a specific token.