In this video, we continue our smart contract interactions using Thirdweb, diving into NFT minting and wallet asset display. This builds upon our previous setup and adds more dynamic, user-centered functionality.
Thirdweb simplifies interacting with smart contracts, including minting NFTs and retrieving owned assets. Key tools we'll use:
These hooks provide an easy-to-use interface for tasks that would otherwise require complex smart contract interaction.
The minting form includes input fields for:
Each field is tied to a React useState variable. When the user submits the form, we run handleSubmit.
Inside handleSubmit, we first check if any of the fields are empty. If so, we return early to avoid submitting invalid data.
After validation, we create the metadata object required for minting. It includes:
We also need the user's wallet address for the to field. To retrieve this, we use the useAddress hook from Thirdweb:
const address = useAddress();
We then call the mintNFT function, passing:
{
metadata: { name, description, image },
to: address,
}
The function handles the blockchain interaction, and the UI responds to:
To let users view their owned NFTs, we build a wallet page using the useOwnedNFTs hook. This hook returns all NFTs owned by a given address.
Steps include:
Example handling:
if (!address) return <p>No wallet detected</p>;
if (isLoading) return <p>Loading NFT data...</p>;
ownedNFTs?.map(nft => (
<NFTCard key={nft.metadata.id} nft={nft} />
));
This results in a responsive wallet interface that updates in real time based on the connected address.
In this video, we successfully:
Swap insights and ask questions about “Learn everything about Chiliz”.
Ask a question or share your thoughts about this lesson.