Metaplex createMetadataAccountV3 How to Populate Context

994 Views Asked by At

I'm trying to utilize the @metaplex-foundation/umi library and came across an issue when setting up the context and invoking the createMetadataAccountV3 function:

const umi = require('@metaplex-foundation/umi');

let myContext = umi.createNullContext();
let myTransaction = metaPlex.createMetadataAccountV3(
    myContext,
    CreateMetadataAccountV3Args
);

While attempting the above, I consistently receive the following error:

InterfaceImplementationMissingError: Tried using ProgramRepositoryInterface but no implementation of that interface was found. Make sure an implementation is registered, e.g. via "context.programs = new MyProgramRepository();".

The SDK documentation suggests using:

context.programs = new MyProgramRepository();

However, it's not entirely clear to me how to properly implement this. Could anyone provide guidance on how to correctly populate myContext and address this error?

2

There are 2 best solutions below

3
azuldev On BEST ANSWER

I found the answer under umi docs.

Not a fan of umi....but it is what it is.

https://github.com/metaplex-foundation/umi/blob/main/docs/installation.md

const myUmi= require('@metaplex-foundation/umi-bundle-defaults');

const umi = myUMI.createUmi('https://api.mainnet-beta.solana.com');

let CreateMetadataAccountV3Args = {
        //accounts
        metadata: metadataAccount,
        mint: polaris_exp_mintKeypair.publicKey,
        mintAuthority: pdaPublicKey,
        payer: feePayerAccount.publicKey,
        updateAuthority: pdaPublicKey,
        // & instruction data
    data: {
      name: "myname",
      symbol: "exp",
      uri: "example_uri.com",
      sellerFeeBasisPoints: 0,
      creators: null,
      collection: null,
      uses: null
    },
    isMutable: true,
    collectionDetails: null,
  }

  const umi = myUMI.createUmi('https://api.mainnet-beta.solana.com');

  let myTransaction = metaPlex.createMetadataAccountV3(
    umi,
    CreateMetadataAccountV3Args
  )

  console.log(myTransaction)
0
Tushar Sahoo On

If you are using umi framework (since "@metaplex-foundation/js" is deprecated), for most contexts you have to pass the defaults from "@metaplex-foundation/js" package. Providing a null context just doesn't provide what the transaction requires.

I know UMI is a bit complex but thats the accepted way now.

So to modify your code:

const { createUmi } = require("@metaplex-foundation/umi-bundle-defaults");
// other imports

// Use the RPC endpoint of your choice.
const RPC_ENDPOINT = "https://api.devnet.solana.com";

const umi = createUmi(RPC_ENDPOINT);

let myTransaction = metaPlex.createMetadataAccountV3(
    umi,
    CreateMetadataAccountV3Args //You need to create this entire type
);

@azuldev has already shown how to create the CreateMetadataAccountV3Args so not repeating it here just wanted to clear that wherever context is required use umi defaults.