Property 'PROGRAM_ID' does not exist on type 'typeof import @metaplex-foundation/mpl-token-metadata'

359 Views Asked by At

I am trying to create a token on Solana network, but I have one problem. I installed @metaplex-foundation/mpl-token-metadata and imported it into my code, but it gives me an error

I'm copying this tutorial: https://awoyemivictor.notion.site/Latest-Solana-Token-Creation-Naming-Updating-Step-by-Step-Guide-for-Beginners-July-2022-fc2d8a4042ec49909047ba87eb3aa85a

Error:Property 'PROGRAM_ID' does not exist on type 'typeof import("d:/Documents/VSC_Files/Token/node_modules/@metaplex-foundation/mpl-token-metadata/dist/src/index")'.

this is the code:

import * as mpl from "@metaplex-foundation/mpl-token-metadata";
import * as web3 from "@solana/web3.js"
import * as anchor from '@project-serum/anchor'

export function loadWalletKey(keypairFile: string): web3.Keypair {
    const fs = require("fs");
    const loaded = web3.Keypair.fromSecretKey(
        new Uint8Array(JSON.parse(fs.readFileSync(keypairFile).toString())),
    );
    return loaded;
}



async function main() {
    console.log("Let's name some tokens");

    const myKeypair = loadWalletKey("AfkbuWt6YuU7xLzUz2M5rBRVpqBcCutyH9895v9YxU6w.json")
    console.log(myKeypair.publicKey.toBase58())
    const mint = new web3.PublicKey("EcUBmCbntM3SniLH54B92TdqR3JexjbW57y8jXmmugxC.json")


    const seed1 = Buffer.from(anchor.utils.bytes.utf8.encode("metadata"));
    const seed2 = Buffer.from(mpl.PROGRAM_ID.toBytes());
    const seed3 = Buffer.from(mint.toBytes());

    const [metadataPDA, _bump] = web3.PublicKey.findProgramAddressSync([seed1, seed2, seed3], mpl.PROGRAM_ID);


    const accounts = {
        metadata: metadataPDA,
        mint,
        mintAuthority: myKeypair.publicKey,
        payer: myKeypair.publicKey,
        updateAuthority: myKeypair.publicKey,
    }


    const dataV2 = {
        name: "Echo Token",
        symbol: "ECHO",
        uri: "https://indigo-efficient-sparrow-269.mypinata.cloud/ipfs/QmbQBemXZBS7Uvhd2LdHauBoZimqmy8vDDKCohAnEx49k6?_gl=1*16nlwuc*_ga*MTI0NzMwNTIwMy4xNzA0MzE5OTIx*_ga_5RMPXG14TE*MTcwNDMxOTkyMi4xLjEuMTcwNDMyMDk0MS42MC4wLjA.",
        
        sellerFeeBasisPoints: 0,
        creators: null,
        collection: null,
        uses: null
    }

    const args = {
        createMetadataAccountArgsV2: {
            data: dataV2,
            isMutable: true
        }
    };

    const ix = mpl.createCreateMetadataAccountV2Instruction(accounts, args);
    const tx = new web3.Transaction();
    tx.add(ix);
    const connection = new web3.Connection("https://api.devnet.solana.com");
    const txid = await web3.sendAndConfirmTransaction(connection, tx, [myKeypair]);
    console.log(txid);



}

main()

I tried to install metaplex js and metaplex umi and import them but it didn't help.

1

There are 1 best solutions below

0
Mark Sackerberg On

first of all please be aware that the latest @metaplex-foundation/mpl-token-metadata package relies on umi, so you will not be able to use the web3js publickey type with it but need the umi publickey type.

Instead of directly calling the instruction you might also want to use the mpl-token-metadata helper method createV1:

await createFungible(umi, {
  mint,
  name: 'Echo Token',
  symbol: 'ECHO',
  uri: 'https://indigo-efficient-sparrow-269.mypinata.cloud/ipfs/QmbQBemXZBS7Uvhd2LdHauBoZimqmy8vDDKCohAnEx49k6?_gl=1*16nlwuc*_ga*MTI0NzMwNTIwMy4xNzA0MzE5OTIx*_ga_5RMPXG14TE*MTcwNDMxOTkyMi4xLjEuMTcwNDMyMDk0MS42MC4wLjA.',
  sellerFeeBasisPoints: percentAmount(0),
}).sendAndConfirm(umi)

(https://developers.metaplex.com/token-metadata/mint#creating-accounts)

If you actually are looking for just the token metadata program id @metaplex-foundation/mpl-token-metadata has it as MPL_TOKEN_METADATA_PROGRAM_ID (https://mpl-token-metadata-js-docs.vercel.app/functions/getMplTokenMetadataProgramId.html)