Skip to content

Quickstart

Prerequisites

Before getting started with Balius, make sure you have the following prerequisites installed:

  1. 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.
  2. 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 dApps
balius-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:

Terminal window
# Install the Balius Cargo plugin
cargo 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:

Terminal window
# Create a new project
cargo balius init my_dapp
cd my_dapp
# Build your project
cargo balius build

Alternatively, you can create a standard Rust project and add Balius dependencies manually:

Terminal window
cargo new my_dapp
cd 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