metaplex-foundation / mpl-token-metadata

Program to attach additional data to Fungible or Non-Fungible tokens on Solana.
https://developers.metaplex.com/token-metadata
Other
143 stars 70 forks source link

createCreateMetadataAccountV3Instruction is missing #123

Closed y0unghe closed 2 months ago

y0unghe commented 4 months ago

I am trying to use the function createCreateMetadataAccountV3Instruction to create an instruction. But I am getting the below error when importing to my Next.js project. The version I am using is the latest. But when I searched for the function in the current Github repo, this function did exist.

"@metaplex-foundation/mpl-token-metadata": "^3.2.1",
'"@metaplex-foundation/mpl-token-metadata"' has no exported member named 'createCreateMetadataAccountV3Instruction'. Did you mean 'CreateMetadataAccountV3InstructionData'?
rosselpha commented 3 months ago

yea. me too

y4my4my4m commented 3 months ago

Same

MarkSackerberg commented 3 months ago

Hey @y0unghe @rosselpha @y4my4my4m where did you find this and Why do you assume that there should be a function like this? createCreateMetadataAccountV3Instruction is a type, not a function. The function for it would be createMetadataAccountV3.

If you actually want to directly use that instruction you could use

import {
  createMetadataAccountV3,
  mplTokenMetadata,
} from "@metaplex-foundation/mpl-token-metadata";
import { none } from "@metaplex-foundation/umi";

  const createMetadataAccountV3Ix = createMetadataAccountV3(umi, {
    mint: mint.publicKey,
    mintAuthority: umi.identity,
    isMutable: true,
    collectionDetails: none(),
    data: {
      name: "myToken",
      uri: "https://arweave.net/7BzVsHRrEH0ldNOCCM4_E00BiAYuJP_EQiqvcEYz3YY",
      symbol: "MT",
      sellerFeeBasisPoints: 0,
      creators: none(),
      collection: none(),
      uses: none(),
    },
  }).getInstructions()

We highly recommend to use the createV1 wrapper though:

import {  createV1,  mplTokenMetadata,  TokenStandard } from "@metaplex-foundation/mpl-token-metadata";

import {
  percentAmount,
} from "@metaplex-foundation/umi";
  const createV1Ix = createV1(umi, {
    mint: mint.publicKey,
    authority: umi.identity,
    name: "My NFT",
    uri: "https://arweave.net/7BzVsHRrEH0ldNOCCM4_E00BiAYuJP_EQiqvcEYz3YY",
    sellerFeeBasisPoints: percentAmount(5.5),
    tokenStandard: TokenStandard.Fungible,
  }).getInstructions()

or, depending on what kind of token you want to create there are Create Helpers that requires even less input. For example createFungible:

  await createFungible(umi, {
    mint,
    name: "myToken",
    uri: "https://arweave.net/7BzVsHRrEH0ldNOCCM4_E00BiAYuJP_EQiqvcEYz3YY",
    sellerFeeBasisPoints: percentAmount(0),
    decimals: tokenAmount.decimals,
  })
xcaptain commented 2 months ago

I find this from https://github.com/solana-developers/pirate-bootcamp/blob/main/quest-1/scripts/3.createTokenWithMetadata.ts#L121 And https://www.youtube.com/watch?v=0P8JeL3TURU&t=1529s

xcaptain commented 2 months ago

Also the official doc recommend using V2 version. https://solana.com/developers/courses/tokens-and-nfts/token-program#make-some-token-metadata

Do you have any examples about how to use createMetadataAccountV3 without using umi ?

MarkSackerberg commented 2 months ago

If you are using the same packages as the package.json of the pirate-bootcamp suggests (which is very outdated) it should be working fine. The Solana.com docs you sent recommends to use package version 2 - which does not require Umi.

Personally i would absolutely recommend to follow our docs in the developer hub on how to use umi and how to create Metadata.

If you don't want to interact with umi more than needed this could work (untested code):

import {
  createMetadataAccountV3,
  mplTokenMetadata,
} from "@metaplex-foundation/mpl-token-metadata";
import { none, createNoopSigner} from "@metaplex-foundation/umi";
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
import { toWeb3JsInstruction } from '@metaplex-foundation/umi-web3js-adapters';

  const umi = createUmi('https://api.devnet.solana.com').use(mplTokenMetadata())

  const createMetadataAccountV3Ix = createMetadataAccountV3(umi, {
    mint: mint.publicKey,
    mintAuthority: createNoopSigner(<your signing wallet pubkey>),
    isMutable: true,
    collectionDetails: none(),
    data: {
      name: "myToken",
      uri: "https://arweave.net/7BzVsHRrEH0ldNOCCM4_E00BiAYuJP_EQiqvcEYz3YY",
      symbol: "MT",
      sellerFeeBasisPoints: 0,
      creators: none(),
      collection: none(),
      uses: none(),
    },
  }).getInstructions()

const web3jsinstruction = toWeb3JsInstruction(createMetadataAccountV3Ix)