Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 7939

Calling transfer function from node server on anchor

$
0
0
Error: AnchorError caused by account: recipient. Error Code: ConstraintMut. Error Number: 2000. Error Message: A mut constraint was violated.
 #![allow(clippy::result_large_err)]use anchor_lang::prelude::*;use anchor_lang::system_program;declare_id!("BwVTNv9QWnp6WqyzUaR5Fmnt5DLJjmtrGVgLY57o3hww");#[program]pub mod transfer_sol {    use super::*;    pub fn transfer_sol_with_cpi(ctx: Context<TransferSolWithCpi>, amount: u64) -> Result<()> {        msg!("Working in transfer_sol_with_cpi function"); // Log message        system_program::transfer(            CpiContext::new(                ctx.accounts.system_program.to_account_info(),                system_program::Transfer {                    from: ctx.accounts.payer.to_account_info(),                    to: ctx.accounts.recipient.to_account_info(),                },            ),            amount,        )?;        Ok(())    }}#[derive(Accounts)]pub struct TransferSolWithCpi<'info> {    #[account(mut)]    payer: Signer<'info>,    #[account(mut)]    recipient: SystemAccount<'info>,    system_program: Program<'info, System>,}

this is how I am calling it

const txSignature = await program.methods    .transferSolWithCpi(new anchor.BN(lamports))    .accounts({        payer: adminWallet.publicKey,        recipient: recipientPubkey,        system_program: anchor.web3.SystemProgram.programId,    })    .rpc();

Viewing all articles
Browse latest Browse all 7939

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>