2

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.

Jmb
  • 18,893
  • 2
  • 28
  • 55
srb
  • 21
  • 2
  • You can read here how to sign with a pda https://solanacookbook.com/references/accounts.html#how-to-sign-with-a-pda – AlexN Jun 28 '22 at 19:10
  • Additionally you can see here how to use pda & spl token program https://betterprogramming.pub/using-pdas-and-spl-token-in-anchor-and-solana-df05c57ccd04 – AlexN Jun 28 '22 at 19:12
  • Thank you for responding @AlexN.https://solanacookbook.com/references/programs.html#how-to-transfer-sol-in-a-program but pda created is used to create a new pda account here. i got confused with the flow of pda creation and transfer. first created pda then an account is needed to act as escrow? i am confused. which accounts are important to instruction.? can you guide.. – srb Jun 29 '22 at 06:41
  • https://solanacookbook.com/references/accounts.html#client-1 is really helpful – srb Jun 29 '22 at 06:55

0 Answers0