Skip to main content

Fetch Collection Nfts

fetch all nfts of a given collection.

Import fetchCollectionNfts using const { fetchCollectionNfts } = MetastaqInstance and pass the collection id for which you want to fetch nfts.

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

export const ShowCollectionsNfts = () => {
const { status, data, error, isFetching, isLoading, refetch } =
fetchCollectionNfts(COLLECTION_ID);

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

COLLECTION_ID is the ID of the collection whose data you want to retrieve.

The method fetchCollectionNFTs 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, and the refetch method lets you retrieve the response again if you want to update the status when you click the button.