Skip to main content
added 163 characters in body
Source Link
john
  • 7.8k
  • 2
  • 10
  • 26

Anchor includes a SystemAccount type that you can use if the expected to account will always be a system program owned account (ex. a user's wallet address).

#[derive(Accounts)]
pub struct Transfer<'info> {
    pub from: Signer<'info>,
    #[account(mut)]
    pub to: SystemAccount<'info>
}

Using the UncheckedAccount type would allow the recipient of the transfer to be any account (such as program account, or an account owned by other program).

You would need to specify that the from account is mutable with #[account(mut)]. Maybe add a test to see if the balances after the transfer actually changes.

Anchor includes a SystemAccount type that you can use if the expected to account will always be a system program owned account (ex. a user's wallet address).

#[derive(Accounts)]
pub struct Transfer<'info> {
    pub from: Signer<'info>,
    #[account(mut)]
    pub to: SystemAccount<'info>
}

Using the UncheckedAccount type would allow the recipient of the transfer to be any account (such as program account, or an account owned by other program).

Anchor includes a SystemAccount type that you can use if the expected to account will always be a system program owned account (ex. a user's wallet address).

#[derive(Accounts)]
pub struct Transfer<'info> {
    pub from: Signer<'info>,
    #[account(mut)]
    pub to: SystemAccount<'info>
}

Using the UncheckedAccount type would allow the recipient of the transfer to be any account (such as program account, or an account owned by other program).

You would need to specify that the from account is mutable with #[account(mut)]. Maybe add a test to see if the balances after the transfer actually changes.

Source Link
john
  • 7.8k
  • 2
  • 10
  • 26

Anchor includes a SystemAccount type that you can use if the expected to account will always be a system program owned account (ex. a user's wallet address).

#[derive(Accounts)]
pub struct Transfer<'info> {
    pub from: Signer<'info>,
    #[account(mut)]
    pub to: SystemAccount<'info>
}

Using the UncheckedAccount type would allow the recipient of the transfer to be any account (such as program account, or an account owned by other program).