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
98 stars 42 forks source link

Transaction simulation failed: Error processing Instruction 3: An account required by the instruction is missing #110

Open strickland84 opened 3 months ago

strickland84 commented 3 months ago

I am trying to create a Fungible SPL-2022 token with metaplex. I believe I'm missing some key piece of the puzzle here so help would be appreciated. My pseudo-code looks like this:

import useUmi from '@/hooks/useUmi'
import { TokenStandard, createV1, mintV1 } from '@metaplex-foundation/mpl-token-metadata'
import { percentAmount, generateSigner, signerIdentity, sol, transactionBuilder, publicKey} from '@metaplex-foundation/umi'

umi.use(signerIdentity(umi.identity));
const mint = generateSigner(umi);

const SPL_TOKEN_2022_PROGRAM_ID = publicKey(
  'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'
);

const transaction = transactionBuilder()
  .add(createV1(umi, {
    mint,
    authority: umi.identity,
    name: token.name,
    symbol: token.symbol,
    uri: metaDataUri,
    sellerFeeBasisPoints: percentAmount(0),
    decimals: token.decimals,
    splTokenProgram: SPL_TOKEN_2022_PROGRAM_ID,
    tokenOwner: umi.identity.publicKey,
    tokenStandard: TokenStandard.Fungible
  }))
  .add(mintV1(umi, {
    mint: mint.publicKey,
    authority: umi.identity.publicKey,
    tokenOwner: mint.publicKey,
    splTokenProgram: SPL_TOKEN_2022_PROGRAM_ID,
    tokenStandard: TokenStandard.Fungible
  }))

transaction.sendAndConfirm(umi).then(() => {
  // Do something
}).catch((error) => {
  console.log(error)
});

When I run this function I receive error:

Transaction simulation failed: Error processing Instruction 3: An account required by the instruction is missing

If I skip preflight, I receive error:

{
    "InstructionError": [
        3,
        "MissingAccount"
    ]
}

Can anyone help enlighten me? What am I missing here? Thanks!

MarkSackerberg commented 3 months ago

Hey @strickland84 there seems to be an issue in how umi derives the token account?

import { findAssociatedTokenPda } from '@metaplex-foundation/mpl-toolbox'

  const token = findAssociatedTokenPda(umi, {
    mint: mint.publicKey,
    owner: umi.identity.publicKey,
    tokenProgramId: SPL_TOKEN_2022_PROGRAM_ID,
  });

const transaction = transactionBuilder()
  .add(createV1(umi, {
    mint,
    authority: umi.identity,
    name: token.name,
    symbol: token.symbol,
    uri: metaDataUri,
    sellerFeeBasisPoints: percentAmount(0),
    decimals: token.decimals,
    splTokenProgram: SPL_TOKEN_2022_PROGRAM_ID,
    tokenOwner: umi.identity.publicKey,
    tokenStandard: TokenStandard.Fungible
  }))
  .add(mintV1(umi, {
    mint: mint.publicKey,
    authority: umi.identity.publicKey,
    token,
    tokenOwner: mint.publicKey,
    splTokenProgram: SPL_TOKEN_2022_PROGRAM_ID,
    tokenStandard: TokenStandard.Fungible
  }))