I'm trying to update primary_sale_happened to true in the metadata's NFT. I have deployed my program with anchor. But when I test it, I have this error printed in the console: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: An account required by the instruction is missing
.
I suppose that I pass wrong inputs to the update_primary_sale_happened_via_token
, but I didn't get what I have to pass to the method.
Here some context.
This is the code that I'm using in the rust program:
invoke(
&mpl_instruction::update_primary_sale_happened_via_token(
TOKEN_METADATA_ID,
ctx.accounts.metadata.key(), // desc="Metadata key (pda of ['metadata', program id, mint id])")
ctx.accounts.owner_authority.key(), // desc="Owner on the token account")
ctx.accounts.owner_token_account.key(), // desc="Account containing tokens from the metadata's mint")
),
&[
ctx.accounts.metadata.to_account_info(),
ctx.accounts.owner_authority.to_account_info(),
ctx.accounts.owner_token_account.to_account_info(),
],
)?;
Note: mpl_instruction
is just an alias of mpl_token_metadata::instruction
And this is the code from my test file:
await program.methods.primarySale(
new anchor.BN(saleAmount)
)
.accounts({
mint: mint,
ownerTokenAccount: ownerTokenAddress, // pass to the update_primary_sale_happened_via_token as fourth param
ownerAuthority: wallet.publicKey, // pass to the update_primary_sale_happened_via_token as third param
buyerTokenAccount: buyerTokenAddress,
buyerAuthority: buyer.publicKey,
metadata: metadataAddress, // pass to the update_primary_sale_happened_via_token as second param
})
.signers([buyer])
.rpc();
I get the metadata with this call:
const metadataAddress = (await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("metadata"),
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
TOKEN_METADATA_PROGRAM_ID
))[0];
The owner_authority is the wallet's publickey which have been used to mint. wallet.publicKey
And the owner_token_account is retrieved with this call:
const ownerTokenAddress = await anchor.utils.token.associatedAddress({
mint: mint,
owner: wallet.publicKey
});
Here are the versions of the libs that I use for the program:
[dependencies]
anchor-lang = "0.25.0"
anchor-spl = "0.25.0"
mpl-token-metadata = { version = "1.4.0", features = ["no-entrypoint"] }
What I'm doing wrong with the accounts? Is there an other account to pass to the method?
Thanks for your help.