简体   繁体   English

我可以将 SOL 从 PDA 帐户转移到 solana 中的另一个普通帐户吗?

[英]Can I transfer SOL from a PDA Account to another normal account in solana?

I have tried sending sol token from my pda account to another account我尝试将 sol 令牌从我的 pda 帐户发送到另一个帐户

 **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我希望只有管理员能够调用此功能并将其转移到任何帐户

The PDA is controlled only by the program. PDA 仅由程序控制。 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.您需要编写的指令需要“管理员”签名,然后可以将灯从 PDA 移动到提供的帐户。

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 .如果您的程序是帐户的owner ,您只能从帐户中扣除灯,这仅在调用assigncreate_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:如果 PDA 仍归系统程序所有,这是默认行为,您需要在 PDA 上使用“签名”在系统程序中执行 CPI,即:

        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]]]
        )?;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM