Guides
Worked example Reading token_vault
token_vault is a small sample program that holds tokens for its users. It opens in Byteatlas with no file needed: open the example and follow along
Updated
1. Scan the instructions
The Instructions view lists everything the program can do. token_vault has five
| Instruction | Arguments | What it does |
|---|---|---|
initialize_vault | none | Creates the vault PDA for a mint |
deposit | amount: u64 | Moves tokens from the user into the vault |
withdraw | amount: u64 | Returns tokens from the vault to the user |
set_authority | new_authority: pubkey | Hands control of the config to a new key |
close_vault | none | Closes the vault and returns its rent |
2. Open deposit
Select deposit to see the five accounts it takes and what each is allowed to do. Reading the roles tells you who must sign and what the instruction can change
| Account | Role | Why |
|---|---|---|
user | signer, writable | The depositor authorises the transfer and pays from their tokens |
vault | writable, PDA | Receives the tokens, so its balance changes |
user_position | writable, PDA | Records how much this user has deposited |
mint | read-only | Identifies which token is being deposited |
token_program | read-only | The SPL Token program that performs the transfer |
3. Check the PDAs
The PDAs view shows where each derived address comes from
vaultis derived from the constant"vault"and themintaccount, so there is exactly one vault per tokenuser_positionis derived from"pos"and theuseraccount, so every user gets their own position record
4. See the whole picture
The Accounts view merges all five instructions. It shows vault is used by four of them, which makes it the account to audit most carefully, while config only appears in set_authority and close_vault