Quickstart
Prerequisites
Before getting started with Balius, make sure you have the following prerequisites installed:
- Rust: Balius is built with Rust, so you’ll need to have Rust installed on your system. You can install Rust by following the official instructions at https://www.rust-lang.org/tools/install.
- Cargo: Cargo is Rust’s package manager and build tool. It comes pre-installed with Rust, so if you have Rust installed, you should already have Cargo.
Installation Options
There are two main ways to use Balius:
Option 1: Add Libraries as Dependencies
For integrating Balius functionality directly into your Rust projects, add the required libraries to your Cargo.toml
:
[dependencies]balius-sdk = "0.1.0" # Core SDK for building headless dAppsbalius-runtime = "0.1.0" # Optional: Runtime for executing dApps
Option 2: Install Balius Tools
For development tools that help with creating, building and testing Balius projects:
# Install the Balius Cargo plugincargo install balius
# Install the Balius daemon (optional)cargo install baliusd
Create a new Balius project
The easiest way to get started is using the Balius Cargo plugin:
# Create a new projectcargo balius init my_dappcd my_dapp
# Build your projectcargo balius build
Alternatively, you can create a standard Rust project and add Balius dependencies manually:
cargo new my_dappcd my_dapp# Then edit Cargo.toml to add the dependencies
Add a hello world script
Here’s a simple example using the balius-sdk:
use balius_sdk::{Config, FnHandler, Params, Json, Worker, WorkerResult};use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]struct SomeConfig {}
#[derive(Serialize, Deserialize)]struct SayHelloParams { name: String,}
#[derive(Serialize, Deserialize)]struct Reply { message: String,}
fn say_hello(_: Config<SomeConfig>, params: Params<SayHelloParams>) -> WorkerResult<Json<Reply>> { Ok(Json(Reply { message: format!("Hello, {}", params.0.name), }))}
#[balius_sdk::main]fn main() -> Worker { Worker::new().with_request_handler("say-hello", FnHandler::from(say_hello))}
Next Steps
- Explore the cargo plugin documentation for more information about the Balius tools
- Check out the examples in the repository
- Learn about the event system for reacting to blockchain activities