metaplex-foundation / metaplex

A directory of what the Metaplex Foundation works on!

Home Page:https://metaplex.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error creating token: TypeError - Cannot read properties of undefined (reading 'toBuffer')

Ai-Artsca opened this issue · comments

GitHub Issue Request

Title: Error creating token: TypeError - Cannot read properties of undefined (reading 'toBuffer')

Description:
We are experiencing an error when attempting to create a token using the provided CreateToken.jsx script. The error occurs during the token metadata creation process. Below are the steps taken and relevant logs.

Steps to Reproduce:

  1. Upload an image to Pinata.
  2. Upload metadata to Pinata.
  3. Create a new token mint and associated token account.
  4. Mint tokens to the created account.
  5. Attempt to create the metadata account using the Metaplex token metadata program.

Logs:

Image uploaded to Pinata: https://gateway.pinata.cloud/ipfs/QmeFRzoFFaN66xbiFxMZcVNCfDyUDiYPThkCTMbTJW4ajT
Metadata uploaded to Pinata: https://gateway.pinata.cloud/ipfs/QmQwG25gBKZ5gWyz6gZv6VMzA9ppiMkKccbHgUx5o2CX8o
Minimum balance for rent exemption: 1461600
Transaction partially signed with mint keypair.
Transaction signed by wallet.
Serialized transaction: Uint8Array(528) [...]
Token created with signature: Gfvp16zCpZXp3bVd6QRGMnrqAd3xf256xVUBzbfN6W1UiQqw5425snQpsgvwDkSc8ojHYWMAGe7XCFn59sNkJiD
Tokens minted with signature: _Transaction {signatures: Array(1), feePayer: _PublicKey2, instructions: Array(3), recentBlockhash: 'GhiM7JYhyeLdiTdC8TRdMXvhf9DH57rgJN82CKrzoMhB', ...}
Serialized mint transaction: Uint8Array(297) [...]
Mint transaction sent with signature: ZqSFUG9bUpj8GMEZEYfhxaFFQgKCViAS2bj2wMkLgRFczTcoFNbxWrEnqeiU6am5BG5hi1mECDKdsk5EwQymy2k
Error creating token: TypeError: Cannot read properties of undefined (reading 'toBuffer')
    at handleSubmit (CreateToken.jsx:240:26)

Relevant Code Snippet:

const metadataPDA = await PublicKey.findProgramAddress(
  [
    Buffer.from("metadata"),
    mpl.PROGRAM_ID.toBuffer(),
    mint.publicKey.toBuffer(),
  ],
  mpl.PROGRAM_ID
);

const metadataAccount = {
  metadata: metadataPDA[0],
  mint: mint.publicKey,
  mintAuthority: publicKey,
  payer: publicKey,
  updateAuthority: publicKey,
};

const metadataData = {
  name: tokenName,
  symbol: ticker,
  uri: metadataUrl,
  sellerFeeBasisPoints: 0,
  creators: null,
  collection: null,
  uses: null,
};

const createMetadataInstruction = mpl.createCreateMetadataAccountV2Instruction(
  metadataAccount,
  {
    createMetadataAccountArgsV2: {
      data: metadataData,
      isMutable: true,
    },
  }
);

Expected Behavior:
The token creation process should complete without errors, and the metadata should be correctly associated with the token.

Actual Behavior:
A TypeError is thrown during the execution of the metadata account creation process, specifically when calling toBuffer().

Steps Taken:

  1. Verified that the image and metadata were successfully uploaded to Pinata.
  2. Ensured that the minimum balance for rent exemption was calculated correctly.
  3. Partially signed the transaction with the mint keypair.
  4. Successfully created the token and minted tokens.
  5. Encountered the error during the metadata account creation.

Environment:

  • Metaplex Token Metadata: @metaplex-foundation/mpl-token-metadata
  • Solana Web3.js: @solana/web3.js
  • React: ^17.0.2

Request:
Assistance in diagnosing and resolving the TypeError related to toBuffer when creating the metadata account. Any insights or suggestions would be greatly appreciated.

Thank you!