Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Ai-Artsca opened this issue May 17, 2024 · 0 comments

Comments

@Ai-Artsca
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant