solana token transfer An account required by the instruction is missing
solana token transfer An account required by the instruction is missing
Loading saved threads...
lsj · External communityPost link
External question — Solana Stack Exchange
Author: lsj
Original post: https://solana.stackexchange.com/questions/15880
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I minted an NFT with anchor and would like to send it to a different address.
NFT Mint address is
BoWAiiGuVTEY7Jsck6KuCoRPMDUgC5wpH84RoRBBNMDS
program
use anchor_spl::token::{mint_to, Mint, MintTo, Token, TokenAccount,TransferChecked,transfer_checked};
pub fn transfer_test(ctx: Context<TransferTest>) -> Result<()> {
let cpi_accounts = TransferChecked {
from: ctx.accounts.from.to_account_info(),
to: ctx.accounts.to_ata.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
mint:ctx.accounts.mint.to_account_info()
};
let cpi_program = ctx.accounts.token_program.to_account_info();
// Create the CpiContext we need for the request
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
transfer_checked(cpi_ctx,1,0)?;
Ok(())
}
#[derive(Accounts)]
pub struct TransferTest<'info> {
#[account(
init_if_needed,
payer = authority,
associated_token::mint = mint,
associated_token::authority = authority,
)]
pub to_ata: Account<'info, TokenAccount>,
#[account(mut)]
pub mint: Account<'info, Mint>,
pub token_program: Program<'info, Token>,
/// CHECK: This is the token account that we want to mint tokens to
#[account(mut)]
pub from: Account<'info, TokenAccount>,
/// CHECK: the authority of the mint account
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub rent: Sysvar<'info, Rent>,
}
test
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
const program = anchor.workspace.Test as Program<Test>;
const authority = provider.wallet.publicKey
const mintAddress = new PublicKey("BoWAiiGuVTEY7Jsck6KuCoRPMDUgC5wpH84RoRBBNMDS");
it("Burns tokens from the token account", async () => {
// Call the burn_token function from the program
const mint = mintAddress;
// Assuming the token account is already created and tokens are minted
const tokenAccount = anchor.utils.token.associatedAddress({
mint: mint,
owner: authority,
});
const to = anchor.utils.token.associatedAddress({
mint: mint,
owner: new PublicKey("H8tmHjLuphAnMqgGdJLWryXp9kySduF53wWcPcvsmkeB"),
});
const params = {
mint:mintAddress,
toAta:to,
from: tokenAccount,
authority: authority,
tokenProgram: TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId,
associatedTokenProgram: ASSOCIATED_PROGRAM_ID,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
}
console.log(params);
await program.methods.transferTest()
.accounts(params)
.rpc({skipPreflight:true});
});
Even after checking
https://docs.rs/anchor-spl/latest/anchor_spl/token/
I'm not sure what I'm doing wrong.
The same error occurs even change
transfer_checked
to
transfer
.
Referring to the answer to a similar question, I tried changing
associated_token::mint
and
associated_token::authority
to
token::mint
and
token::authority
, but a
Missing signature for public key
error occurred.
token
https://solscan.io/token/BoWAiiGuVTEY7Jsck6KuCoRPMDUgC5wpH84RoRBBNMDS?cluster=devnet
transaction
https://solscan.io/tx/3exA7f26WviFWK7Jh78jn2H7VZdZ6TZ5yAqVmik2GGfewVfD7U1MosBH8s2G7KMEpccHxog6TWXLhXVUnz9EV5CH?cluster=devnet
Quote
Report
Mohammed Alabd · External communityPost link
External answer — Solana Stack Exchange
Author: Mohammed Alabd
Original post: https://solana.stackexchange.com/a/23115
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
the error is likely not coming from the transfer instruction, it seems that it is throwing before reaching there, you are passing an account as writable, but it not even initialized
Czzu5Bm3hR7Su3BrxB9Mr775YGfFwXCjndd4KAski4sa
the logs:
Program logged: "Instruction: RequestPrize"
Instruction references an unknown account Czzu5Bm3hR7Su3BrxB9Mr775YGfFwXCjndd4KAski4sa
Program consumed: 11330 of 200000 compute units
Program returned error: "An account required by the instruction is missing"
Quote
Report
Post Reply
Checking account access…