CDK Reference
Complete reference for the Rialo Rust crates � rialo-cdk, rialo-venus-dsl, rialo-sol-lang, and supporting libraries.
On this page
Crate overview
| Crate | Version | Purpose |
|---|---|---|
rialo-cdk |
0.9.x | Primary on-chain program library. Targets both native (tokio async) and wasm32. |
rialo-venus-dsl |
0.9.x | Async workflow DSL � rialo! macro, AFTER / EVERY / ON / SEND / START. |
rialo-sol-lang |
0.9.x | Solana Sealevel eDSL (Anchor-compatible). For porting or writing SVM-layer programs. |
rialo-s-program |
0.9.x | Low-level on-chain program crate (Solana program layer). Use when you need direct SVM access. |
rialo-s-sdk |
0.9.x | Client-side Rust SDK. Use this to interact with deployed programs from off-chain code. |
rialo-s-feature-set |
0.9.x | Feature flags and capability detection for the Rialo runtime. |
rialo-cdk
The primary library for building on-chain programs. It re-exports everything you need and provides the core abstractions: context, token operations, events, accounts, and native primitives.
Prelude
rust
use rialo_cdk::prelude::*;
// Brings into scope: Context, Pubkey, Result, require!, emit!,
// Clock, token, https, price_feed, messaging, random, schedule
Core types
| Type | Description |
|---|---|
Context | Transaction context � ctx.signer, ctx.accounts, ctx.auth_token |
Pubkey | 32-byte on-chain address |
Result<T> | Rialo result type, maps to ProgramResult |
Duration | Time span � Duration::seconds(n), Duration::days(n) |
Clock | On-chain clock � Clock::get().unix_timestamp |
Macros
| Macro | Description |
|---|---|
require!(cond, err) | Assert condition or return error. Equivalent to if !cond { return Err(err) } |
emit!(event) | Emit a typed on-chain event from a struct decorated with #[event] |
msg!(fmt, ...) | Log a message to the transaction log (debug use) |
token module
rust
// Native token transfer
token::transfer(from: Pubkey, to: Pubkey, amount: u64) -> Result<()>
// Stable token transfer (USDC / protocol stablecoin)
token::transfer_stable(to: Pubkey, amount: u64) -> Result<()>
// Get token balance
token::balance(account: Pubkey) -> Result
// Mint new tokens (requires mint authority)
token::mint(to: Pubkey, amount: u64) -> Result<()>
// Burn tokens
token::burn(from: Pubkey, amount: u64) -> Result<()>
https module
rust
// GET request � returns HttpResponse
https::get(url: impl Into) -> Result
// POST request with JSON body
https::post(url: impl Into, body: &impl Serialize) -> Result
// HttpResponse methods
response.status() -> u16
response.text() -> String
response.json::() -> Result // deserializes into type T
response.headers() -> HashMap
price_feed module
rust
// Latest price (u64, scaled by 10^6)
price_feed::get(pair: &str) -> Result
// Price with confidence interval
price_feed::get_with_confidence(pair: &str) -> Result
// PriceWithConfidence { price: u64, confidence: u64, expo: i32 }
// Time-weighted average price
price_feed::twap(pair: &str, window: Duration) -> Result
// Event trigger conditions (used with ON keyword)
price_feed::below(pair: &str, threshold: u64) -> EventCondition
price_feed::above(pair: &str, threshold: u64) -> EventCondition
price_feed::change(pair: &str, pct_bps: i64) -> EventCondition
random module
rust
// Random u64 in [min, max)
random::range(min: u64, max: u64) -> u64
// Random bytes
random::bytes(len: usize) -> Vec
// Random bool with probability p (0..=100)
random::bool_with_prob(p: u8) -> bool
messaging module
rust
// Send to wallet (IBE-encrypted, delivered to device)
messaging::send(recipient: Pubkey, message: &str) -> Result<()>
// Send to email address (no wallet needed)
messaging::send_email(email: &str, message: &str) -> Result<()>
// Send to phone number
messaging::send_sms(phone: &str, message: &str) -> Result<()>
// Send push notification (requires device token from social login)
messaging::send_push(device_id: &str, message: &str) -> Result<()>
rialo-venus-dsl
Provides the rialo! proc-macro and the Venus async DSL keywords. See the Venus DSL reference for full usage documentation.
Macro entry point
rust
use rialo_venus_dsl::rialo;
rialo! {
state { /* fields */ }
program { /* functions + async ops */ }
}
Async operation syntax
| Keyword | Syntax | Description |
|---|---|---|
AFTER | AFTER <duration> => fn() | Run once after delay |
EVERY | EVERY <duration> => fn() | Run repeatedly on interval |
ON | ON <condition> => fn() | Run when event/condition fires |
SEND | SEND fn(args) | Non-blocking async message |
START | START WorkflowName { fields } | Spawn new workflow instance |
rialo-sol-lang
An Anchor-compatible eDSL for writing Solana Sealevel programs on Rialo. If you're familiar with Anchor, this will feel identical � it's a drop-in replacement that targets the Rialo SVM layer.
rust
use rialo_sol_lang::prelude::*;
#[program]
pub mod my_program {
use super::*;
pub fn initialize(ctx: Context, data: u64) -> Result<()> {
ctx.accounts.my_account.data = data;
Ok(())
}
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = user, space = 8 + 8)]
pub my_account: Account<'info, MyAccount>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[account]
pub struct MyAccount {
pub data: u64,
}
rialo-s-sdk (client)
Use rialo-s-sdk to interact with deployed programs from client-side Rust code (off-chain, native async).
toml
# Client binary Cargo.toml
[dependencies]
rialo-s-sdk = "0.9"
tokio = { version = "1", features = ["full"] }
rust
use rialo_s_sdk::{
client::RpcClient,
signature::{Keypair, Signer},
transaction::Transaction,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = RpcClient::new("https://testnet.rialo.io");
let payer = Keypair::read_from_file("~/.config/rialo/id.json")?;
// Call a program instruction
let ix = my_program::instruction::increment(
&my_program::ID,
&payer.pubkey(),
);
let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&payer.pubkey()),
&[&payer],
client.get_latest_blockhash().await?,
);
let sig = client.send_and_confirm_transaction(&tx).await?;
println!("Transaction: {}", sig);
Ok(())
}
Cargo.toml templates
On-chain program (Venus DSL)
toml
[package]
name = "my-program"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
rialo-cdk = "0.9"
rialo-venus-dsl = "0.9"
borsh = "1"
serde = { version = "1", features = ["derive"] }
[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
On-chain program (Anchor-compatible)
toml
[package]
name = "my-anchor-program"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
rialo-sol-lang = "0.9"
rialo-s-program = "0.9"
[features]
no-entrypoint = []
cpi = ["no-entrypoint"]
idl-build = ["rialo-sol-lang/idl-build"]
Client application
toml
[package]
name = "my-client"
version = "0.1.0"
edition = "2021"
[dependencies]
rialo-s-sdk = "0.9"
tokio = { version = "1", features = ["full"] }
anyhow = "1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"