readContract

Reads state from a deployed smart contract.

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

Example

Using a contract read extension

import { getContract } from "thirdweb";
import { sepolia } from "thirdweb/chains";
import { useReadContract } from "thirdweb/react";
import { getOwnedNFTs } form "thirdweb/extensions/erc721";
const contract = getContract({
client,
address: "0x...",
chain: sepolia,
});
const { data, isLoading } = useReadContract(getOwnedNFTs, { contract, owner: address });

Using a raw contract call

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 promise that resolves with the result of the read call.