A high-performance, trait-based Solana program framework for building fast, reliable, and type-safe programs.
Star Frame is a modern Solana program framework designed to make developing on-chain programs more ergonomic, safe, and performant. Built with a trait-based architecture, it provides:
- Performance: Optimized for Solana's compute unit constraints by utilizing Pinocchio and our
unsized_typesystem (check out the Compute Units benchmark vs Anchor). - Developer Experience: Intuitive APIs with comprehensive compile-time validation (traits and types all the way down!).
- Modularity: Everything is a trait or a type, so you can use what you need when you need it. For example, the entrypoint is a method on the
StarFrameProgramtrait, and client/cpi account sets are associated types of theClientAccountSetandCpiAccountSettraits.
Star Frame is in active development (and improving our docs is a main priority now!). If you need help:
- Check out the API documentation
- Browse the examples in this repository
- Open an issue for bug reports or feature requests
- Join our Star Atlas Discord and chat in our
#community-developerschannel
cargo install star_frame_cli
sf --helpsf new <PROJECT-NAME>Add star_frame and bytemuck to your Cargo.toml:
cargo add star_frame bytemuckUse the prelude to import the most commonly used traits and macros:
use star_frame::prelude::*;Below is a simple counter program demonstrating the basic features of Star Frame. In this example, only the designated authority can increment the counter. See the full example for additional useful features.
use star_frame::prelude::*;
#[derive(StarFrameProgram)]
#[program(
instruction_set = CounterInstructionSet,
id = "Coux9zxTFKZpRdFpE4F7Fs5RZ6FdaURdckwS61BUTMG"
)]
pub struct CounterProgram;
#[derive(InstructionSet)]
pub enum CounterInstructionSet {
Initialize(Initialize),
Increment(Increment),
}
#[zero_copy(pod)]
#[derive(ProgramAccount, Default, Debug, Eq, PartialEq)]
pub struct CounterAccount {
pub authority: Pubkey,
pub count: u64,
}
#[derive(BorshSerialize, BorshDeserialize, Debug, InstructionArgs)]
pub struct Initialize {
#[ix_args(run)]
pub start_at: u64,
}
#[derive(AccountSet)]
pub struct InitializeAccounts {
#[validate(funder)]
pub authority: Signer<Mut<SystemAccount>>,
#[validate(arg = Create(()))]
pub counter: Init<Signer<Account<CounterAccount>>>,
pub system_program: Program<System>,
}
#[star_frame_instruction]
fn Initialize(account_set: &mut InitializeAccounts, start_at: u64) -> Result<()> {
**account_set.counter.data_mut()? = CounterAccount {
authority: *account_set.authority.pubkey(),
count: start_at,
};
Ok(())
}
#[derive(BorshSerialize, BorshDeserialize, Debug, Copy, Clone, InstructionArgs)]
pub struct Increment;
#[derive(AccountSet, Debug)]
pub struct IncrementAccounts {
pub authority: Signer,
pub counter: Mut<Account<CounterAccount>>,
}
#[star_frame_instruction]
fn Increment(accounts: &mut IncrementAccounts) -> Result<()> {
ensure!(
*accounts.authority.pubkey() == accounts.counter.data()?.authority,
ProgramError::IncorrectAuthority
);
let mut counter = accounts.counter.data_mut()?;
counter.count += 1;
Ok(())
}Star Frame is built against the latest stable Solana Rust Release: https://github.com/anza-xyz/rust. The minimum supported version is currently 1.84.1.
This project is licensed under the Apache-2.0 license.