I want to transfer some lamports (100) froma a PDA to an account. This is the Rust code:
pub fn test(ctx: Context<ApproveEscrow>) -> Result<()> {
// PDA already initilized in another function and with 1 SOL amount
let pda: &mut Account<ApproverAccount> = &mut ctx.accounts.pda;
let seed: Pubkey = ctx.accounts.receiver.key();
let bump_seed: u8 = ctx.bumps.pda;
let signer_seeds: &[&[&[u8]]] = &[&[b"pda", seed.as_ref(), &[bump_seed]]];
let cpi_context: CpiContext<Transfer> = CpiContext::new(
ctx.accounts.system_program.to_account_info(),
Transfer {
from: pda.to_account_info(),
to: ctx.accounts.receiver.to_account_info(),
}
).with_signer(signer_seeds);
transfer(cpi_context, 100)?;
Ok(())
}
and this ts test code:
it("Test", async () => {
await program.methods
.test()
.accounts({ receiver: receiver.publicKey })
.signers([ receiver ])
.rpc();
}
Everything seems to work correctly, I logged every public keys and they are correct, yet I cannot understand why the transfer function returns: Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: invalid program argument
I'm also sure the PDA account has enough balance to make the transfer. I think it's a signer problem but I really cannot get the problem and the error message does not help so much