metaplex-foundation / js

A JavaScript SDK for interacting with Metaplex's programs
357 stars 182 forks source link

NftNotFoundError [MetaplexError]: NFT > NFT Not Found error on calling nfts().create({uri}) #165

Closed nikhilasrani closed 2 years ago

nikhilasrani commented 2 years ago

Hi folks,

We are getting this error occasionally on creation of an NFT with the Metaplex JS SDK. We run the upload metadata function and get an arweave URI as a response, when we want to create an NFT with that URI, we use the following code snippet where the uri is the arweave uri returned after uploading metadata successfully.

  const { nft } = await metaplex.nfts().create({
      uri,
    });

Now this works almost always except in cases where it throws the below error

NftNotFoundError [MetaplexError]: NFT > NFT Not Found
>> Source: Plugin > NFT
>> Problem: No Metadata account could be found for the provided mint address: [7htki4AQLjiMmS8Y3wgq87CRpHS2ymjMZHWtcQiEmgR].
>> Solution: Ensure the provided mint address is valid and that an associated Metadata account exists on the blockchain.
at Object.handle (/app/node_modules/@metaplex-foundation/js/dist/cjs/plugins/nftModule/findNftByMint.cjs:23:13)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async /app/node_modules/@metaplex-foundation/js/dist/cjs/utils/Task.cjs:67:23
at async Disposable.run (/app/node_modules/@metaplex-foundation/js/dist/cjs/utils/Disposable.cjs:30:14)
at async NftClient.create (/app/node_modules/@metaplex-foundation/js/dist/cjs/plugins/nftModule/NftClient.cjs:53:17)
at async createTableJSNext (/app/services/table.service.js:211:21)
at async /app/controllers/table.controller.js:33:19 {
key: 'metaplex.errors.plugin.nft.nft_not_found',
title: 'NFT > NFT Not Found',
problem: 'No Metadata account could be found for the provided mint address: [7htki4AQLjiMmS8Y3wgq87CRpHS2ymjMZHWtcQiEmgR].',
solution: 'Ensure the provided mint address is valid and that an associated Metadata account exists on the blockchain.',
source: 'plugin',
sourceDetails: 'NFT',
cause: undefined,
logs: undefined
}

Could you please help us figure out what could be causing this issue.

Also any advice on what alternative we could implement to ensure an NFT is always created like maybe calling the create function again or recursively until it gives us an NFT?

lorisleiva commented 2 years ago

Hi there 👋

Are you 100% sure that the transaction went through and the NFT was indeed created?

Alternatively, this could be happening because of commitment settings and so when we try to fetch the NFT, it's not yet been finalized on-chain.

nikhilasrani commented 2 years ago

hey @lorisleiva , It looks like the transaction did go through on-chain and the NFT was indeed created. I was able to see the above mentioned NFT(7htki4AQLjiMmS8Y3wgq87CRpHS2ymjMZHWtcQiEmgR) with its metadata and attributes on Solana Explorer (for devnet).

So the NFT was created and it returned an NFT not found error on executing this code snippet

const { nft } = await metaplex.nfts().create({
      uri,
    });

Since you mentioned that this could be because of the commitment settings, We are using the 'confirmed' commitment level. Could you let me know if this is correct or we should use another commitment setting? We are using the following code for your reference, It works almost always but it does throw this NFT Not Found error in some rare cases.

import { Metaplex } from "@metaplex-foundation/js";
const { Connection, clusterApiUrl, Keypair } = require('@solana/web3.js');

const connection = new Connection(RPC_URL, 'confirmed'); // RPC_URL is our private RPC_URL from Quicknode
 const metaplex = Metaplex.make(connection)
          .use(keypairIdentity(keypair))
          .use(
            bundlrStorage({
              address: 'https://devnet.bundlr.network',
              providerUrl: 'https://api.devnet.solana.com',
              timeout: 60000,
            }),
          );

     const { uri } = await metaplex.nfts().uploadMetadata({
     ... // NFT metadata properties
     })
      const { nft } = await metaplex.nfts().create({
      uri,
    });
nikhilasrani commented 2 years ago

Hey @lorisleiva, I tried changing the commitment level to 'finalized' instead of 'confirmed' and now instead of NFT Not Found, we end up getting a timeout error. I'm pasting the error below

{"status":400,"data":{"statusCode":400,"message":"Failed to Confirm Transaction\n>> Source: RPC\n>> Problem: The transaction could not be confirmed.\n>> Solution: Check the error below for more information.\n\nCaused By: TransactionExpiredTimeoutError: Transaction was not confirmed in 60.00 seconds. It is unknown if it succeeded or failed. Check signature 4QwadkYY1sZnC6VbKP1zZ3Y3h6Bc9Y7qmQybRARbjtmBWvg6jjbbttm3UMGTjqK4z7eTnhRMDarupvYKM2pjcSNG using the Solana Explorer or CLI tools.\n"}}

It appears that the NFT was created for this case as well and is visible on chain and in the wallet.

I'm not sure if there is something we can do about this since there is no state between 'confirmed' and 'finalized'. Please let us know if there is an optimal way/strategy to create NFTs with the library without either of these errors (NFT Not Found on 'confirmed' and Timeout on 'finalized')

lorisleiva commented 2 years ago

Hey 👋 Could you please provide a public repo with the minimum steps to reproduce this bug? I'm struggling to reproduce it. 😕

nikhilasrani commented 2 years ago

Hi @lorisleiva, an update from my end. I think changing commitment level as you suggested from confirmed to finalized seemed to solve the NFT Not Found error. After switching commitment levels, we got a different type of error where the transaction took longer and ended up timing out in the default configuration in some rare cases. To fix this, we also changed the confirmTransactionInitialTimeout to 2 minutes instead of the default 1 minute on the connection configuration as well as the bundlrStorage configuration. We also started using our custom RPC URL instead of the default public RPC URL for the providerUrl in the configuration of the bundlr storage that we use while initializing the metaplex js library.

I am closing this issue. Thank you for your assistance. I will re-open the issue in case this issue shows up again and I will also make a public repo to reproduce the bug if it does show up again. Thanks again for being so prompt and supportive. 🙂

lorisleiva commented 2 years ago

Thank you for the update!