Hey there!
In this short article I'll show you how to convert AccountInfo
or UncheckedAccount
to Account
. We assume that the given account is an PDA.
For a given struct:
pub struct User {
pub account: Pubkey,
}
And in our instructions we have an:
#[derive(Accounts)]
#[instruction()]
pub struct UserInstruction<'info> {
#[account()]
/// CHECK:
pub user: AccountInfo<'info>,
pub fn get_user(ctx: Context<UserInstruction>) -> Result<()> {
let user: Account<User> = Account::try_from(&ctx.accounts.user)?;
// do something here
Ok(())
}
Top comments (0)