Steel
Steel is a lightweight framework for building smart contracts on Solana. It provides of a set of helper functions, macros, and code patterns for organizing cotract codebases. Steel is generally designed to be unopinionated, removing common boilerplate and leaving as much flexibility as possible.
Notes
- This codebase is under active development. All interfaces are subject to change.
- There is currently no CLI or custom localnet toolchain. Build your programs with
solana build-sbf. - The account "loaders" currently do not yet return readable or mutable account references.
- The API macros currently do not support IDL generation.
File structure
While not strictly enforced, we recommend organizing your Solana program with the following file structure. We have found this pattern improves code readability, separating the contract interface from its implementation, and scales well for more complex contracts.
Cargo.toml (workspace)
⌙ api
⌙ Cargo.toml
⌙ src
⌙ consts.rs
⌙ error.rs
⌙ event.rs
⌙ instruction.rs
⌙ lib.rs
⌙ loaders.rs
⌙ sdk.rs
⌙ state
⌙ mod.rs
⌙ account_1.rs
⌙ account_2.rs
⌙ program
⌙ Cargo.toml
⌙ src
⌙ lib.rs
⌙ instruction_1.rs
⌙ instruction_2.rs
API
Steel offers a collection of simple macros for defining your contract API and the basic building blocks of your program.
Accounts
use ;
use ;
use *;
account!;
Instructions
use ;
use TryFromPrimitive;
use *;
instruction!;
Errors
use IntoPrimitive;
use *;
use Error;
error!;
Events
use ;
use *;
event!;
Program
In your instruction implementations, Steel offers helper functions for validating common types of accounts and executing CPIs.
Loaders
use *;
/// Initialize ...
CPIs
use *;