I am trying to write a simple anchor program that will burn the SPL tokens that the user sends to my anchor program. I followed the guide below on QuickNode to build a new program that allows minting.
QuickNode Guide I followed
I then modified the code a bit so that when the user sends SOL to the program, it calculates how much of the SPL Token to mint and sends it back to the users ATA account they provded.
I am now trying to do it the other way around. I want to have the user send the SPL token to the function in the program. Burn the token, and then send sol back.
I followed a couple guides, however, I cant seem to find if it is possible to burn the SPL token right then and there, or if I have to have them transfer the SPL to another program owned PDA and then burn it there.
Is there a way to just have instruction for the SPL token to be burned right when its sent to the program function?
I followed a couple guides including Burning Guide but they all seem to need the program to own the token before they are burned.
I also checked out this documentation and it just seems like gibberish to me without someone to explain it. Burn Information Solana
I am trying to write a simple anchor program that will burn the SPL tokens that the user sends to my anchor program. I followed the guide below on QuickNode to build a new program that allows minting.
QuickNode Guide I followed
I then modified the code a bit so that when the user sends SOL to the program, it calculates how much of the SPL Token to mint and sends it back to the users ATA account they provded.
I am now trying to do it the other way around. I want to have the user send the SPL token to the function in the program. Burn the token, and then send sol back.
I followed a couple guides, however, I cant seem to find if it is possible to burn the SPL token right then and there, or if I have to have them transfer the SPL to another program owned PDA and then burn it there.
Is there a way to just have instruction for the SPL token to be burned right when its sent to the program function?
I followed a couple guides including Burning Guide but they all seem to need the program to own the token before they are burned.
I also checked out this documentation and it just seems like gibberish to me without someone to explain it. Burn Information Solana
Share Improve this question asked Nov 19, 2024 at 22:24 Robert GrospitchRobert Grospitch 31 silver badge2 bronze badges1 Answer
Reset to default 0Yes, sure I provide solana anchor program code for burning tokens that are sent from user to solana program.
pub fn burn(
ctx: Context<CycleBurnToken>,
amount: u64
) -> Result<()> {
let cpi_accounts = Burn {
mint: ctx.accounts.token_mint.to_account_info(),
from: ctx.accounts.pool_token_account.to_account_info(),
authority: ctx.accounts.vault_authority.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);
// Execute anchor's helper function to burn tokens
token::burn(cpi_ctx.with_signer(&[&[
BurningPool::AUTHORITY_PREFIX.as_bytes(),
&ctx.accounts.pool.key().as_ref(),
&[ctx.accounts.pool.vault_bump],
]]),
amount)?;
Ok(())
}