In this video, we implemented the Index Page of our NFT marketplace. This page displays all the listed NFTs available for sale, including their metadata and a “Buy” button to allow users to purchase NFTs directly from the marketplace.
The index page is designed to:
We use the ListingCard component to render each NFT listing dynamically.
To load active listings:
const { contract: marketplace } = useContract(getMarketplaceAddress(), "marketplace-v3");
Each ListingCard displays:
We use a custom image tag and format values manually for a responsive layout.
Unlike other interactions, buying an NFT does not have a dedicated Thirdweb hook, so we handle it manually.
Retrieve the listing using the marketplace contract:
const listing = await marketplace.directListings.getListing(nft.asset.id);
Handle the buying process with:
await marketplace.directListings.buyFromListing(listing.id, 1);
Wrap everything in a try-catch block to manage errors gracefully:
try {
setMessage("Buying...");
const result = await buyFunction();
if (result.receipt) {
setMessage("Bought!");
}
} catch (error) {
console.error(error);
setMessage("Error buying!");
}
We show:
This enhances the user experience and prevents broken flows.
In this implementation:
With the Index Page now functional, users can view and purchase NFTs seamlessly from the decentralized marketplace.
Swap insights and ask questions about “Learn everything about Chiliz”.
Ask a question or share your thoughts about this lesson.