System Program
The Arch System Program is the core program that manages fundamental account operations on the Arch Network. This program provides essential functionality for account creation, ownership management, UTXO anchoring, and lamport transfers.
Overview
The System Program handles:
- Account Creation: Creating new accounts with specified ownership and data allocation
- UTXO Integration: Anchoring accounts to Bitcoin UTXOs for native Bitcoin integration
- Ownership Management: Transferring account ownership between programs
- Lamport Transfers: Moving lamports (the base unit of value) between accounts
- Space Allocation: Allocating data storage space for accounts
Available Instructions
CreateAccount
Creates a new account with the specified parameters.
Parameters:
lamports: u64
- Number of lamports to transfer to the new accountspace: u64
- Number of bytes of memory to allocateowner: Pubkey
- Address of the program that will own the new account
Account References:
[WRITE, SIGNER]
Funding account (payer)[WRITE, SIGNER]
New account to create
Example:
#![allow(unused)] fn main() { use arch_program::{ system_instruction, pubkey::Pubkey, }; let instruction = system_instruction::create_account( &from_pubkey, &to_pubkey, 1_000_000, // lamports 165, // space in bytes &owner_pubkey, ); }
CreateAccountWithAnchor
Creates a new account and anchors it to a specific Bitcoin UTXO.
Parameters:
lamports: u64
- Number of lamports to transferspace: u64
- Number of bytes to allocateowner: Pubkey
- Program that will own the accounttxid: [u8; 32]
- Bitcoin transaction IDvout: u32
- Output index in the Bitcoin transaction
Account References:
[WRITE, SIGNER]
Funding account[WRITE, SIGNER]
New account to create
Example:
#![allow(unused)] fn main() { let instruction = system_instruction::create_account_with_anchor( &from_pubkey, &to_pubkey, 1_000_000, // lamports 165, // space &owner_pubkey, txid, // Bitcoin transaction ID vout, // Bitcoin output index ); }
Assign
Changes the owner of an existing account.
Parameters:
owner: Pubkey
- New owner program
Account References:
[WRITE, SIGNER]
Account to reassign
Example:
#![allow(unused)] fn main() { let instruction = system_instruction::assign( &account_pubkey, &new_owner_pubkey, ); }
Anchor
Anchors an existing account to a Bitcoin UTXO.
Parameters:
txid: [u8; 32]
- Bitcoin transaction IDvout: u32
- Output index
Account References:
[WRITE, SIGNER]
Account to anchor
Transfer
Transfers lamports from one account to another.
Parameters:
lamports: u64
- Amount to transfer
Account References:
[WRITE, SIGNER]
Source account[WRITE]
Destination account
Example:
#![allow(unused)] fn main() { let instruction = system_instruction::transfer( &from_pubkey, &to_pubkey, 500_000, // lamports to transfer ); }
Allocate
Allocates space in an account without funding it.
Parameters:
space: u64
- Number of bytes to allocate
Account References:
[WRITE, SIGNER]
Account to allocate space for
Example:
#![allow(unused)] fn main() { let instruction = system_instruction::allocate( &account_pubkey, 1024, // bytes to allocate ); }
Error Handling
The System Program can return the following errors:
AccountAlreadyInUse
- Account with the same address already existsResultWithNegativeLamports
- Account doesn’t have enough lamports for operationInvalidProgramId
- Cannot assign account to this program IDInvalidAccountDataLength
- Cannot allocate account data of this lengthMaxSeedLengthExceeded
- Requested seed length is too longAddressWithSeedMismatch
- Address doesn’t match derived seed
Important Constants
#![allow(unused)] fn main() { // Minimum lamports required for any account pub const MIN_ACCOUNT_LAMPORTS: u64 = 1024; // Maximum permitted data length for accounts pub const MAX_PERMITTED_DATA_LENGTH: usize = 10 * 1024 * 1024; // 10MB }
Best Practices
Account Creation
- Always fund with sufficient lamports: Accounts need at least
MIN_ACCOUNT_LAMPORTS
to be created - Use appropriate space allocation: Allocate only the space you need to minimize costs
- Set correct ownership: Ensure the owner program can properly manage the account
UTXO Integration
- Verify UTXO existence: Ensure the referenced Bitcoin UTXO exists and is confirmed
- Use proper confirmation counts: Wait for sufficient Bitcoin confirmations before using anchored accounts
- Handle reorgs gracefully: Account for potential Bitcoin reorganizations
Security Considerations
- Validate signers: Always verify that required accounts are properly signed
- Check ownership: Verify account ownership before operations
- Handle edge cases: Account for insufficient funds, invalid parameters, etc.
Integration with Bitcoin
The System Program’s UTXO anchoring functionality enables direct integration with Bitcoin:
- Account-UTXO Mapping: Accounts can be directly linked to Bitcoin UTXOs
- Ownership Verification: Bitcoin signatures can prove account ownership
- State Synchronization: Account states can be synchronized with Bitcoin state
This integration provides:
- Native Bitcoin security guarantees
- Direct UTXO management capabilities
- Seamless Bitcoin transaction integration
- Provable ownership and state anchoring
Related Documentation
- Account Model - Understanding Arch’s account structure
- Instructions and Messages - How instructions work
- Bitcoin Integration - Bitcoin-native features
- UTXO Management - Working with Bitcoin UTXOs