Skip to main content

Fetch Contract's Nfts

fetch all nfts from a contract related to given account address.

Import fetchContractNfts using const { fetchContractNfts } = MetastaqInstance and pass the given details for which you want to fetch nfts.

fetchContractNfts
import React from "react";
import { MetastaqInstance } from "./MetastaqInstance";

export const ShowContractNfts = () => {
const { status, data, error, isFetching, isLoading, refetch } =
fetchContractNfts(web3, abi, contractAddress, accountAddress);

return (
<button
onClick={() => {
refetch();
}}
>
refetch collection's nfts
</button>
);
};

where web3 is the web3 instance.

The method fetchContractNFTs returns status, data, error, isFetching, isLoading, refetch, where data is the collection related data, status tells you the success or failure status of the response, error tells you the error message, isFetching and isLoading are Boolean values that tell you the status whether the request is still running or not. The refetch method lets you retrieve the response again if you want to update the status when you click the button.