admin管理员组文章数量:1336293
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(())
}
本文标签: Can I burn SPL Tokens that are sent from a user to a Solana ProgramStack Overflow
版权声明:本文标题:Can I burn SPL Tokens that are sent from a user to a Solana Program? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742394647a2466676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论