> ## 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.

# Type conversions

> Convert between Anchor and Solana types

Anchor provides utilities for converting between Anchor types and raw Solana types.

## AccountInfo conversion

Convert Anchor accounts to `AccountInfo`:

```rust theme={null}
let account_info = ctx.accounts.my_account.to_account_info();
```

## Key extraction

Get the public key from any account:

```rust theme={null}
let pubkey = ctx.accounts.my_account.key();
```

## Borrowing account data

Access raw account data:

```rust theme={null}
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`:

```rust theme={null}
let my_account = Account::<MyAccount>::try_from(&account_info)?;
```

## Program ID access

```rust theme={null}
let program_id = ctx.accounts.my_program.key();
// or
let program_id = *ctx.program_id;
```

## Complete example

```rust theme={null}
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(())
}
```
