How to get the last NFT minted on candy machine

482 views Asked by At

After a user mints an nft, I want to get the token address or metadata and display it.

I'm using the Candy machine's ui from Metaplex

They're using the mintOneToken function and it only returns a confirmation code, and that's not helpful.

 const mintTxId = (
   await mintOneToken(candyMachine, wallet.publicKey)
 );

Response

confirmationStatus: "confirmed"

I tried calling another function I got from Solana's cookbook , to get all the nfts minted by the current users wallet address.

But I think it fetches the data before the wallet gets updated and it doesn't retrieve the latest NFT minted


  const updateNfts = async () => {
    
    if (wallet.connected) {

      const ownerPublickey = wallet.publicKey;
      const nftsmetadata = await Metadata.findDataByOwner(connection, ownerPublickey);

      if(nftsmetadata.length>0){
        const amountOfNFT = nftsmetadata.length;
        console.log(nftsmetadata[amountOfNFT - 1]);
      }
    }

  }


How can I get the latest metadata to display it for the users? Should i set a timeout ?

0

There are 0 answers