Documentation Index
Fetch the complete documentation index at: https://mintlify.com/solana-foundation/anchor/llms.txt
Use this file to discover all available pages before exploring further.
Anchor provides utilities for converting between Anchor types and raw Solana types.
AccountInfo conversion
Convert Anchor accounts to AccountInfo:
let account_info = ctx.accounts.my_account.to_account_info();
Get the public key from any account:
let pubkey = ctx.accounts.my_account.key();
Borrowing account data
Access raw account data:
let data = ctx.accounts.my_account.try_borrow_data()?;
let mut data = ctx.accounts.my_account.try_borrow_mut_data()?;
Converting from AccountInfo
Load an Anchor account from AccountInfo:
let my_account = Account::<MyAccount>::try_from(&account_info)?;
Program ID access
let program_id = ctx.accounts.my_program.key();
// or
let program_id = *ctx.program_id;
Complete example
pub fn process(ctx: Context<Process>) -> Result<()> {
// Get AccountInfo
let account_info = ctx.accounts.data.to_account_info();
// Get key
let key = ctx.accounts.data.key();
// Access raw data
let data = account_info.try_borrow_data()?;
Ok(())
}