-
Notifications
You must be signed in to change notification settings - Fork 119
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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? 🤔
No description provided.