useReadContract

Signature #1

A hook to read state from a contract that automatically updates when the contract changes.

You can use raw read calls or read extensions to read from a contract.

Example

import { getContract } from "thirdweb";
import { sepolia } from "thirdweb/chains";
import { useReadContract } from "thirdweb/react";
const contract = getContract({
client,
address: "0x...",
chain: sepolia,
});
const { data, isLoading } = useReadContract({
contract,
method: "function tokenURI(uint256 tokenId) returns (string)"});
params: [1n],
});

Parameters

Returns

a UseQueryResult object.

Signature #2

A hook to read state from a contract that automatically updates when the contract changes. You can use raw read calls or read extensions to read from a contract.

Example

Read a contract extension let you do complex contract queries with less code.

import { useReadContract } from "thirdweb/react";
import { getOwnedNFTs } form "thirdweb/extensions/erc721";
const { data, isLoading } = useReadContract(getOwnedNFTs, { contract, owner: address });

Parameters

Returns

a UseQueryResult object.