1

I'm currently developing an escrowed NFT sale contract and when I try to update the primary_sale_happened field of an NFT, after paying the creators and right before transferring it, I get this error Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing.

I know it comes from this function call because commenting it removes the error.

pub const VAULT_AUTHORITY_PREFIX: &[u8] = b"VAULT_AUTHORITY";

// [...]

let (_vault_authority, vault_authority_bump) =
    Pubkey::find_program_address(&[VAULT_AUTHORITY_PREFIX], &id());
let authority_seeds = &[&VAULT_AUTHORITY_PREFIX[..], &[vault_authority_bump]];

// [...]

mpl_update_primary_sale_happened_via_token(
    &self.metadata.to_account_info(),
    &self.vault_authority.to_account_info(),
    &self.vault_account.to_account_info(),
    authority_seeds,
)?;

Here is its definition (copied from metaplex/fixed-price-sale):

#[inline(always)]
pub fn mpl_update_primary_sale_happened_via_token<'a>(
    metadata: &AccountInfo<'a>,
    owner: &AccountInfo<'a>,
    token: &AccountInfo<'a>,
    signers_seeds: &[&[u8]],
) -> Result<()> {
    let tx = mpl_token_metadata::instruction::update_primary_sale_happened_via_token(
        mpl_token_metadata::id(),
        metadata.key(),
        owner.key(),
        token.key(),
    );

    invoke_signed(
        &tx,
        &[metadata.clone(), owner.clone(), token.clone()],
        &[&signers_seeds],
    )?;

    Ok(())
}

And here is the Context:

#[derive(Accounts)]
#[instruction(price: u64)]
pub struct Buy<'info> {
    #[account(mut)]
    pub buyer: Signer<'info>,

    #[account(mut)]
    pub buyer_token_account: Account<'info, TokenAccount>,

    pub mint: Account<'info, Mint>,

    /// CHECK: Not dangerous. Account seeds and owner checked in constraint.
    #[account(
        mut,
        seeds = [
            mpl_token_metadata::state::PREFIX.as_bytes(),
            mpl_token_metadata::id().as_ref(),
            mint.key().as_ref()
        ],
        bump,
        seeds::program = mpl_token_metadata::id(),
        constraint = !metadata.data_is_empty(),
        constraint = metadata.owner == &mpl_token_metadata::id(),
    )]
    pub metadata: UncheckedAccount<'info>,

    /// CHECK: This is not dangerous because we don't read or write from this account
    #[account(mut)]
    pub seller: UncheckedAccount<'info>,

    #[account(
        mut,
        seeds = [Sale::PREFIX.as_ref(), mint.key().as_ref()],
        bump,
        has_one = seller,
        has_one = mint,
        constraint = price == sale.price,
        close = seller
    )]
    pub sale: Account<'info, Sale>,

    #[account(
        mut, 
        seeds = [VAULT_PREFIX.as_ref(), mint.key().as_ref()],
        bump,
        token::mint = mint,
        token::authority = vault_authority,
    )]
    pub vault_account: Account<'info, TokenAccount>,

    /// CHECK: This is not dangerous because we don't read or write from this account
     #[account(
        seeds = [VAULT_AUTHORITY_PREFIX.as_ref()],
        bump,
    )]
    pub vault_authority: UncheckedAccount<'info>,

    pub token_program: Program<'info, Token>,
    pub system_program: Program<'info, System>,
}

I'm pretty confident (but cannot be 100% sure) that the arguments are valid since I can read the metadata (so the Metadata account seems okay) and later on transfer the NFT from vault_account whose owner is vault_authority (so they must be valid too...).

I'm also wondering if the issue could come from my local-validator ? I started it with a dump of metaplex's token-metadata program and the other functionalities seem to work juste fine... (using this command solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s dumps/metadata.so --reset)

Does anyone know how to fix this error please ?

2
  • Also I have since then changed the way I retrieve the vault_authority_bump using ctx.bumps, making it kinda better computationally wise but does not fix my issue in any way Aug 10, 2022 at 14:53
  • are you still stuck with this issue ser ?
    – Pratik.js
    Sep 22, 2022 at 11:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.