Quickstart#
From nothing to a program running on Solana, typed into and checked, in about ten minutes.
1. Try it in the browser#
The playground runs the same core as the Solana program, compiled to WebAssembly. Linux boots and logs in by itself; type a command and watch the count of transactions it would take on Solana. You can also pick the loan calculator, or load your own RISC-V ELF.
2. Run a machine locally#
You need Rust (with cargo build-sbf from the Solana tools) and this repository.
Build the program and start solux-localnet, a local validator with the
program loaded (it runs on Windows, macOS and Linux):
cd programs/solux && cargo build-sbf && cd ../..
cargo run --release --manifest-path crates/sim/Cargo.toml --bin localnet
In a second terminal, install the CLI and build the starter program (it totals the amounts you type):
cargo install --path crates/cli
cd guest/starter && cargo build --release && cd ../..
Boot it. The CLI makes a throwaway payer for the local validator, creates the two accounts, uploads the program compressed, checks the upload byte for byte, then sends Steps until the program asks for input:
solux boot guest/starter/target/riscv32im-unknown-none-elf/release/starter --ram 1M --per-step 13000 --until "> "
machine 6WYiRtg5bgqeafxRpsLpcT6KrLRqNTZDgbhsK7e5q7fh ram Ctrv9uXKSD1BSErtXUaQMooPdX4ZCcigTgdifvNSL9HF (1048576 bytes, rent 5.355 SOL)
uploading 1048576 bytes as 8 compressed chunks (6946 bytes) in 1 waves
RAM verified: on-chain account matches the local image
Solux starter. Type amounts, one per line; an empty line prints the total.
console printed "> "
Type into it (one Type transaction), then let it finish:
solux type '12.50\n7.25\n\n'
solux crank --per-step 13000
> 12.50
> 7.25
>
Total 19.75 (2 items)
machine powered off
Close it to get the rent back:
solux close
--per-step 13000 because a program that waits for keys in a loop costs about
twice as many compute units per instruction as plain computation. Without it,
the CLI measures the first Step and adapts on its own.
3. Do the same from TypeScript#
import { SoluxClient, verifyMachine } from "@solux/sdk";
const solux = new SoluxClient({ rpc: "http://127.0.0.1:8899", payer });
const machine = await solux.createMachine(starterElf, { ramSize: 1 << 20 });
await solux.crank(machine, { until: "> " });
await solux.type(machine, "12.50\n7.25\n\n");
const { lines } = await solux.crank(machine); // [..., "Total 19.75 (2 items)"]
const check = await verifyMachine(solux.rpc, machine.machine); // check.ok === true
See the SDK guide for the details.