0

Using Candy Machine v2, Candy Machine UI and metaplex-foundation/js.

Following https://solanacookbook.com/references/nfts.html#how-to-get-nft-metadata as my basis, I am trying to get the metadata of the NFT that was just minted by the user.

if (status && !status.err && metadataStatus) {
      // manual update since the refresh might not detect
      // the change immediately
      let remaining = itemsRemaining - 1;
      setItemsRemaining(remaining);
      setIsActive((candyMachine.state.isActive = remaining > 0));
      candyMachine.state.isSoldOut = remaining === 0;
      setSetupTxn(undefined);
      setAlertState({
        open: true,
        message: "Congratulations! Mint succeeded!",
        severity: "success",
        hideDuration: 7000,
      });
      refreshCandyMachineState("processed");

      // CODE TO GET METADATA
      const keypair = Keypair.generate();

      const metaplex = new Metaplex(props.connection);
      metaplex.use(keypairIdentity(keypair));

      const nft = await metaplex.nfts().findByMint(mintResult.mintPublicKey);
      console.log("NFT: ", nft);
      console.log(nft.metadata);

    }

The issue I run into is that the nft status is still pending, and nft.metadata is none.

1 Answer 1

1

You would have to wait until the transaction has been finalized e.g. with connection.confirmTransaction before trying to read the metadata from chain.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.