Programs
Programs are the executable code used to perform actions on the BBAChain blockchain.
Overview
Programs in BBAChain are similar to smart contracts in other blockchains. They are executable code that runs on the network and can interact with accounts.
Program Structure
Programs in BBAChain:
- Are written in Rust or C
- Are compiled to BPF (Berkeley Packet Filter) bytecode
- Are deployed to the network as executable accounts
- Can be upgraded if the program is marked as upgradeable
Program Execution
When a transaction includes an instruction that invokes a program:
- The program's executable account is loaded
- The program's entrypoint is called with the instruction data
- The program processes the instruction
- The program can read and modify accounts
- The program returns success or an error
Writing Programs
BBAChain programs are typically written in Rust using the bbachain-program crate:
use bbachain_program::{
account_info::AccountInfo,
entrypoint,
entrypoint::ProgramResult,
pubkey::Pubkey,
};
entrypoint!(process_instruction);
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
// Program logic here
Ok(())
}
Program Accounts
Programs can own accounts to store state. These accounts are controlled by the program and can only be modified by the program itself.
Program Upgrades
If a program is marked as upgradeable, it can be upgraded by the upgrade authority. This allows programs to be updated with new features or bug fixes.
Next Steps
- Learn about Transactions
- Understand Accounts
- Explore Cross-Program Invocation