- Basic program invocation guide - fundamentals of queuing computations and defining callback instructions
- Callback Type Generation - how output types like AddTogetherOutputare automatically generated from encrypted instructions
- Arcis inputs/outputs - handling encrypted data types
- Storing computation results in persistent accounts
- Updating game state, user balances, or protocol data
- Writing results that exceed transaction size limits
Complete Example
Expanding on our basic example, let’s say we want to save the result of our addition in an account for later use. We’ll walk through the complete implementation step by step.Step 1: Define the Account Structure
First, define an account to store our computation result:Step 2: Modify the Queue Function
There are two ways to specify callback instructions in yourqueue_computation call:
Recommended: Using callback_ix() Helper
Thecallback_ix() helper method is the preferred approach because it automatically handles the 3 required standard accounts and is less error-prone.
What callback_ix() does automatically:
- Creates a CallbackInstruction with the proper instruction data
- Automatically includes 3 standard accounts: arcium_program,comp_def_account,instructions_sysvar
- Accepts custom accounts through the &[CallbackAccount]parameter
- Eliminates boilerplate and prevents errors
Understanding What Happens: Manual CallbackInstruction
For educational purposes, here’s whatcallback_ix() generates under the hood. This manual approach is functionally equivalent but more verbose and error-prone:
callback_ix() method automatically generates the exact same CallbackInstruction structure as the manual approach, but with less code and reduced chance for errors.
Important: We added the account to the callback (either via callback_ix() parameter or CallbackInstruction.accounts) but didn’t include it in the AddTogether accounts struct because we don’t read or write to it during the queue function - only during the callback.
Step 3: Implement the Callback Function
The callback instruction receives the accounts in the exact order specified in the queue function:Key Requirements & Constraints
Account Ordering
The accounts in your callback struct must match exactly the order inCallbackInstruction.accounts:
- First three accounts are always standard (arcium_program, comp_def_account, instructions_sysvar)
- Custom accounts follow in the exact sequence you specified
Account Creation Rules
- Can create accounts in the queue computation function (user pays rent)
- Cannot create accounts during callback execution (would require nodes to pay)
- Accounts must exist before the callback executes
- Account size cannot change during callback
Writability Requirements
- Set is_writable: truein CallbackAccount to tell nodes to mark the account as writable
- The account must have #[account(mut)]in the callback struct
- Without proper writability flags, mutations will fail
Troubleshooting
Account not found: Ensure the account exists before callback execution. Initialize it in the queue function or a separate instruction. Order mismatch errors: Double-check that your callback struct accounts are in the exact same order as the CallbackInstruction.accounts vector. Cannot modify account: Verify bothis_writable: true in CallbackAccount and #[account(mut)] in the callback struct are set.
Size errors: Callback accounts cannot be resized. Allocate sufficient space when creating the account.
Understanding callback_ix() in Detail
Thecallback_ix() method you see throughout these examples is a convenient helper that’s automatically generated by the #[callback_accounts] macro.
How callback_ix() Works
When you define a callback struct with#[callback_accounts("instruction_name")], the macro automatically generates a callback_ix() method that:
- Creates a CallbackInstruction with the proper instruction data
- Automatically includes 3 standard accounts that every callback needs:
- arcium_program: The Arcium program that will invoke your callback
- comp_def_account: The computation definition account for your encrypted instruction
- instructions_sysvar: Solana’s instructions sysvar for transaction validation
 
- Accepts custom accounts through the &[CallbackAccount]parameter
Usage Patterns
Basic usage (no custom accounts):Why Use callback_ix()?
Thecallback_ix() helper is the recommended approach because it:
- Eliminates boilerplate: No need to manually construct CallbackInstruction
- Prevents errors: Automatically includes all required standard accounts
- Maintains consistency: Ensures your callback instructions follow the correct format
- Simplifies maintenance: Changes to callback requirements are handled by the macro