Skip to content

Mint specific nft #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

MGoldstein18
Copy link
Contributor

No description provided.

Copy link
Contributor

@nachoiacovino nachoiacovino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some things to change but the bigger questions is how are you keeping up with which NFTs have been minted already without a db

import { useEffect, useState } from 'react';
import { useAddress, useNFTCollection, useMetamask } from '@thirdweb-dev/react';

const Nfts = (props: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the correct typing here?

const [nftMetadata, setNftMetadata] = useState([null]);

// useEffect hook to get NFTs from API
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convert this to try/catch async/await

const nftCollection = useNFTCollection(nftCollectionAddress);

// Function which generates signature and mints NFT
async function onClick(id: number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be an arrow function? rest is good, you did async/await here :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, rename it to mintNft

connectWithMetamask();
setLoading(true);
// Call API to generate signature and payload for minting
const response = await fetch('/api/getNfts', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const response = await fetch('/api/getNfts', {
const response = await fetch('/api/getNfts', {

can we change the name of the endpoint to get-nfts?

<SimpleGrid justifyItems='center' columns={3} spacing={10}>
{nftMetadata?.map((nft: any) => (
<Box
key={nftMetadata.indexOf(nft)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
key={nftMetadata.indexOf(nft)}
key={nftMetadata.indexOf(nft)}

not recommended to use indexs as keys, you can use the id of the nft itself

// Function which generates signature and mints NFT
async function onClick(id: number) {
try {
connectWithMetamask();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why we have this on the same function instead of checking first if the user has connected their wallet?

res: NextApiResponse
) {
// Read and format the NFT data
const rawData = fs.readFileSync(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to do this? can't you just import the JSON directly in the imports?


dotenv.config();

export interface NFT {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get this interface from our SDK, feel free to extend it if you need "minted" and "price", its called NFTMetadataInput, create an interface and share it between the frontend and the backend

// Update the minted status of the NFT to true so that it can't be minted again
const newNFTs = nfts;
newNFTs[id].minted = true;
fs.writeFileSync('pages/api/data/nfts.json', JSON.stringify(newNFTs));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you make sure this stays changed? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants