2

I want to send SOL from PDA to Pubkey. I have saved some addresses in a Vec and now I want to send SOL on these accounts from the PDA account which holds the SOL. How can I send SOL on to these accounts? I found many solutions where the Recipient address is type AccountInfo. Is there any way to send SOL without using the type of Recipient address AccountInfo.

**Code:**
impl Participant {
    pub fn new(address: Pubkey, amount: u64) -> Self {
        Participant { address, amount }
    }
}

// struct for AllParticipants PDA
#[account]
pub struct AllParticipants {
    pub participants: Vec<Participant>,
}



#[derive(Accounts)]
#[instruction(name: String)]
pub struct Create<'info> {
    #[account(init, payer=admin, space=9000, seeds=["lottery".as_ref(),name.as_ref()], bump)]
    pub lottery: Account<'info, Lottery>,
    #[account(
        init,
        payer = admin,
        space = AllParticipants::SIZE,
        seeds = ["account".as_ref(),name.as_ref()],
        bump
    )]
    pub all_participants: Account<'info, AllParticipants>,
    #[account(mut)]
    pub admin: Signer<'info>,
    pub system_program: Program<'info, System>,
}

**Main Functionality**

for i in 0..all_participants.participants.len() {
            let user = &mut all_participants.participants[i];
            if user.address == _winner {
                if deposit_amount < user.amount {
                    return Err(ProgramError::Custom(403));
                }
                **ctx
                    .accounts
                    .lottery
                    .to_account_info()
                    .try_borrow_mut_lamports()? -= user.amount;
                **admin.to_account_info().try_borrow_mut_lamports()? += user.amount;
                (&mut ctx.accounts.lottery).deposit_amount -= user.amount;
                (&mut ctx.accounts.lottery).winner = _winner;
                all_participants.participants.remove(i);
                break;
            }

1 Answer 1

3

If I understand correctly, you want to send SOL to pubkeys that are not passed as accounts to your instruction. This is not possible.

Solana achieves high TPS partly due to its ability to parallelize instruction execution. For this to work, validators must know in advance all the accounts that will be impacted by each instruction. This avoids conflicts where two simultaneous instructions modify the same account.

Given this, in order to modify an account, even just to send SOL to it, you need to include it into the instruction's accounts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.