Is it possible to use Anchor to transfer SOL from user wallet into another user wallet without actually having to initialize program accounts?
I know someone may think that this can be easily done directly in JavaScript but I need this to be in Rust, to be able to charge fees within an Anchor program.
#[derive(Accounts)]
pub struct PayFees<'info> {
pub sender: Signer<'info>,
#[account(mut, constraint = ALLOWED_PUBKEY_OF_THE_RECEIVER == receiver.key())]
pub receiver: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
}
pub fn pay_fees(ctx: Context<PayFees>) -> Result<()> {
let fee_transfer_cpi_context = CpiContext::new(
ctx.accounts.system_program.to_account_info(),
system_program::Transfer {
from: ctx.accounts.sender.to_account_info(),
to: ctx.accounts.receiver.to_account_info(),
},
);
system_program::transfer(fee_transfer_cpi_context, 1_000_000_000)?;
Ok(())
}
Would it be safe to do something like this? I am not really aware of the risks of using an UncheckedAccount.