| Crates.io | star_frame |
| lib.rs | star_frame |
| version | 0.25.1 |
| created_at | 2023-11-16 23:32:46.951265+00 |
| updated_at | 2025-09-11 19:43:55.463168+00 |
| description | A high performance Solana framework for building fast, scalable, and secure smart contracts. |
| homepage | |
| repository | https://github.com/staratlasmeta/star_frame |
| max_upload_size | |
| id | 1038397 |
| size | 481,622 |
star_frame
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:
unsized_type system (check out the Compute Units benchmark vs Anchor).StarFrameProgram trait, and client/cpi account sets are associated types of the ClientAccountSet and CpiAccountSet traits.Star Frame is in active development (and improving our docs is a main priority now!). If you need help:
#community-developers channelcargo install star_frame_cli
sf --help
sf new <PROJECT-NAME>
Add star_frame and bytemuck to your Cargo.toml:
cargo add star_frame bytemuck
Use 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.
use star_frame::{anyhow::ensure, 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)]
#[program_account(seeds = CounterSeeds)]
pub struct CounterAccount {
pub authority: Pubkey,
pub count: u64,
}
#[derive(Debug, GetSeeds, Clone)]
#[get_seeds(seed_const = b"COUNTER")]
pub struct CounterSeeds {
pub authority: Pubkey,
}
#[derive(Debug)]
pub struct Authority(Pubkey);
impl AccountValidate<Authority> for CounterAccount {
fn validate_account(self_ref: &Self::Ref<'_>, arg: Authority) -> Result<()> {
ensure!(arg.0 == self_ref.authority, "Incorrect authority");
Ok(())
}
}
/// Initialize the counter
#[derive(BorshSerialize, BorshDeserialize, Debug, InstructionArgs)]
pub struct Initialize {
#[ix_args(&run)]
pub start_at: Option<u64>,
}
#[derive(AccountSet)]
pub struct InitializeAccounts {
#[validate(funder)]
pub authority: Signer<Mut<SystemAccount>>,
#[validate(arg = (
Create(()),
Seeds(CounterSeeds { authority: *self.authority.pubkey() }),
))]
#[idl(arg = Seeds(FindCounterSeeds { authority: seed_path("authority") }))]
pub counter: Init<Seeded<Account<CounterAccount>>>,
pub system_program: Program<System>,
}
#[star_frame_instruction]
fn Initialize(account_set: &mut InitializeAccounts, start_at: &Option<u64>) -> Result<()> {
**account_set.counter.data_mut()? = CounterAccount {
authority: *account_set.authority.pubkey(),
count: start_at.unwrap_or(0),
};
Ok(())
}
/// Increment the counter by 1
#[derive(BorshSerialize, BorshDeserialize, Debug, Copy, Clone, InstructionArgs)]
pub struct Increment;
#[derive(AccountSet, Debug)]
pub struct IncrementAccounts {
pub authority: Signer,
#[validate(arg = Authority(*self.authority.pubkey()))]
pub counter: Mut<ValidatedAccount<CounterAccount>>,
}
#[star_frame_instruction]
fn Increment(account_set: &mut IncrementAccounts) -> Result<()> {
let mut counter = account_set.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.