Rust Reference
The Rust implementation is alx-protocol, published on crates.io. The crate is a peer implementation of the core protocol: the crate creates, validates, and traces Blocks from the same rules as the JavaScript and Python packages and is checked against the same conformance vectors.
Implementation
| Resource | Location |
|---|---|
| Crate | alx-protocol |
| Registry | crates.io |
| Install (library) | cargo add alx-protocol (import as alx_protocol) |
| Install (binaries) | cargo install alx-protocol installs alx and conformance_adapter |
| Requirements | A Rust toolchain with edition 2021 |
Create and Validate a Block
Add the crate and serde_json, then run the program. The program prints the same blockHash as the JavaScript script in Quick Start. Operations return Err(String) on failure, with the error identifier in brackets at the start of the message. Parse Block JSON received from another system with decode_strict_json_bytes() to reject invalid UTF-8, duplicate members, and trailing data.
[dependencies]
alx-protocol = "1"
serde_json = "1"
use alx_protocol::{create_block, validate_block_detailed};
use serde_json::json;
fn main() -> Result<(), String> {
let block = create_block(json!({"type": "note", "text": "Hello ALX"}), &[])?;
let result = validate_block_detailed(&block)?;
println!("{}", block.block_hash);
println!("{}", result.ok);
Ok(())
}
0xe501e2ad688365e24523f3ceda68958aa53aa13eb63dbda953c3690c119faa0a
true
Command-Line Binary
The alx binary validates and traces Block files. Both commands parse the file strictly. conformance_adapter is the process the conformance runner drives; Run Conformance Tests describes the interface. The commands:
| Command | Input |
|---|---|
alx validate <file> | A Block, or a JSON array of Blocks. Validates each Block and the parent structure. |
alx trace <blockHash> --file <file> | A JSON array of Blocks. Prints each reachable ancestor by depth. |
Capabilities
Every core capability is supported, together with the optional Merkle, Ed25519, and P-256 extensions; EIP-712 signing is not bundled. The Implementation Parity table on SDK Reference lists each capability.
When to Use Rust
Choose this crate for verifiers, services, and tooling where a compiled, dependency-light implementation matters. The crate computes the same identities as the JavaScript and Python packages for the same content and parent set.