i was trying to transfer sol from programmatically created wallet to user wallet(withdraw operation).i read documents saying that pda accounts should be create .i created one with my limited knowledge but encountered this error my rust code for pda and withdraw is:
let accounts_iter = &mut accounts.iter();
let coinflip_account = next_account_info(accounts_iter)?;
let wallet_account = next_account_info(accounts_iter)?;
let pda_account = next_account_info(accounts_iter)?;
let system_program = next_account_info(accounts_iter)?;
let withdraw = spl_token::instruction::transfer(
system_program.key,
coinflip_account.key,
wallet_account.key,
&pda_account.key,
&[&pda],
lamports,
)?;
msg!("amount {:?} Fani", lamports);
invoke_signed(
&withdraw,
&[
system_program.clone(),
wallet_account.clone(),
coinflip_account.clone(),
pda_account.clone()
],
signers,
)?;
keys for transaction instruction from typescript is :
keys: [
{ pubkey: coinflipPubKey, isSigner: false, isWritable: true },
{ pubkey: wallet.publicKey, isSigner: true, isWritable: true },
{ pubkey: pda, isSigner: false, isWritable: false },
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
],
where coinflipPubKey is sender ,wallet is user wallet / receiver.