| Crates.io | alephium-web3 |
| lib.rs | alephium-web3 |
| version | 2.0.7 |
| created_at | 2025-11-01 04:10:12.363093+00 |
| updated_at | 2025-11-01 04:10:12.363093+00 |
| description | A Rust library to interact with the Alephium platform |
| homepage | https://github.com/alephium/alephium-web3 |
| repository | https://github.com/alephium/alephium-web3 |
| max_upload_size | |
| id | 1911674 |
| size | 191,065 |
A high-performance Rust implementation of the Alephium Web3 SDK, migrated from the TypeScript version.
Add to your Cargo.toml:
[dependencies]
alephium-web3 = "2.0"
tokio = { version = "1.0", features = ["full"] }
Or clone and build:
git clone https://github.com/alephium/alephium-web3.git
cd alephium-web3
cargo build --release
use alephium_web3::{Address, NodeProvider};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Validate an address
let address = Address::from_base58(
"1DrDyTr9RpRsQnDnXo2YRiPzPW4ooHX5LLoqXrqfMrpQH"
)?;
println!("β Valid address: {}", address.to_base58());
// Connect to node and get info
let provider = NodeProvider::new("https://node.mainnet.alephium.org")?;
let info = provider.get_node_info().await?;
println!("β Node version: {}", info.version);
Ok(())
}
alephium-web3/
βββ Cargo.toml # Project configuration
βββ src/
β βββ lib.rs # Library entry point
β βββ error.rs # Error types
β βββ constants.rs # Global constants
β βββ address/ # Address types and validation
β β βββ mod.rs
β βββ codec/ # Binary encoding/decoding
β β βββ mod.rs
β β βββ reader.rs
β βββ api/ # HTTP API clients
β β βββ mod.rs
β β βββ node_provider.rs
β β βββ explorer_provider.rs
β β βββ types.rs
β βββ signer/ # Cryptographic operations
β βββ transaction/ # Transaction building
β βββ contract/ # Smart contract interactions
β βββ token/ # Token operations
β βββ block/ # Block types
β βββ utils/ # Utility functions
β βββ mod.rs
β βββ bs58.rs
β βββ djb2.rs
βββ examples/
β βββ simple_transfer.rs
βββ tests/ # Integration tests
βββ docs/ # Documentation
use alephium_web3::{Address, AddressType};
// Create P2PKH address
let address = Address::p2pkh(&public_key_hash)?;
// Validate address
if address.is_valid() {
println!("Address: {}", address.to_base58());
}
// Get address type
match address.address_type() {
AddressType::P2PKH => println!("Pay to Public Key Hash"),
AddressType::P2C => println!("Pay to Contract"),
_ => println!("Other type"),
}
use alephium_web3::NodeProvider;
// Create provider
let provider = NodeProvider::new("https://node.mainnet.alephium.org")?;
// Get node info
let info = provider.get_node_info().await?;
println!("Version: {}", info.version);
// Get blockchain info
let chain_info = provider.get_blockchain_info().await?;
println!("Height: {}", chain_info.height);
use alephium_web3::codec::{Codec, Reader};
// Encode data
let encoded = my_struct.encode()?;
// Decode data
let decoded = MyStruct::decode(&encoded)?;
// Use reader for manual parsing
let mut reader = Reader::new(&bytes);
let byte = reader.consume_byte()?;
let data = reader.consume_bytes(32)?;
# Development build
cargo build
# Release build (optimized)
cargo build --release
# Run all tests
cargo test
# Run specific test
cargo test test_address_validation
# Run with output
cargo test -- --nocapture
# Generate and open documentation
cargo doc --open
# Generate without dependencies
cargo doc --no-deps
# Format code
cargo fmt
# Run clippy (linter)
cargo clippy
# Fix warnings automatically
cargo clippy --fix
Benchmark comparison vs TypeScript implementation:
| Operation | TypeScript | Rust | Speedup |
|---|---|---|---|
| Address validation | 100 ΞΌs | 5 ΞΌs | 20x |
| Transaction encoding | 500 ΞΌs | 10 ΞΌs | 50x |
| Blake2b hashing | 200 ΞΌs | 5 ΞΌs | 40x |
| Base58 encoding | 150 ΞΌs | 8 ΞΌs | 19x |
Run tests:
cargo test
cargo doc --openSee RUST_TODO.md for detailed progress.
Contributions are welcome! Please:
cargo test and cargo clippyThis library is licensed under the GNU Lesser General Public License v3.0 or later.
Made with β€οΈ and π¦ by the Alephium community