1

I have tried sending sol token from my pda account to another account

 **pdaaccount.to_account_info().try_borrow_mut_lamports()? -= 12000;
    **receiver.to_account_info().try_borrow_mut_lamports()? += 12000;
   

This only works if the account calling this function is also the receiver. I want only the admin to be able to call this function and transfer it to any account

TylerH
  • 20,799
  • 66
  • 75
  • 101
fahad
  • 111
  • 2
  • Your question helped me more than the answers. I was transfering to the caller, so this method worked, with a few tweaks – nipunasudha Aug 13 '22 at 13:48

2 Answers2

0

The PDA is controlled only by the program. As the program owner you can write any instruction you want.

The instruction you'd need to write would need to require the "admin's" signature, and could then move lamports from PDA to provided account.

Kyano
  • 174
  • 1
  • 8
0

You can only deduct lamports from an account if your program is the owner of the account, which only happens during a call to assign or create_account.

If the PDA is still owned by the system program, which is the default behavior, you'll need to perform a CPI into the system program with a "signature" on your PDA, ie:

        invoke_signed(                                                            
            &system_instruction::transfer(pda_account_info.key, recipient_account_info.key, lamports),                                             
            &[                          
                pda_account_info.clone(),
                recipient_account_info.clone(),
            ],
            &[&[&pda_seed1.as_ref(), &[pda_bump_seed]]]
        )?;
Jon C
  • 7,019
  • 10
  • 17