Chaincraft: A high-performance framework for blockchain prototyping and production-ready decentralized protocols
Chaincraft: A high-performance library for blockchain prototyping and production-ready decentralized protocols. Chaincraft Rust provides a clean, well-documented implementation of core blockchain concepts with a focus on performance, security, and production-stability.
- High Performance: Built with Rust for maximum performance and memory safety
- Educational Focus: Well-documented code with clear explanations of blockchain concepts
- Modular Design: Pluggable consensus mechanisms, storage backends, and network protocols
- Cryptographic Primitives: Ed25519, ECDSA/secp256k1, VRF, Proof-of-Work, VDF, symmetric encryption (Fernet)
- Network Protocol: P2P networking with peer discovery and message propagation
- Flexible Storage: Memory and persistent storage options with optional SQLite indexing
- CLI Interface: Easy-to-use command-line interface for node management
cargo install chaincraftgit clone https://github.com/jose-blockchain/chaincraft-rust.git
cd chaincraft-rust
cargo build --releaseStart a Chaincraft node with default settings:
chaincraft-cli startOr with custom configuration:
chaincraft-cli start --port 8080 --max-peers 20 --debugchaincraft-cli keygenAdd Chaincraft Rust to your Cargo.toml:
[dependencies]
chaincraft = "0.2.4"use chaincraft::{ChaincraftNode, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut node = ChaincraftNode::builder()
.port(21000)
.max_peers(10)
.build()?;
println!("Starting node {} on port {}", node.id(), node.port());
node.start().await?;
// Your application logic here
node.stop().await?;
Ok(())
}use chaincraft::{ChaincraftNode, Result};
#[tokio::main]
async fn main() -> Result<()> {
let mut node = ChaincraftNode::builder()
.port(21000)
.max_peers(50)
.with_persistent_storage(true) // requires feature "persistent"
.local_discovery(true)
.persist_peers(true)
.build()?;
node.start().await?;
// Node is now running with persistent storage and local discovery
Ok(())
}Chaincraft Rust is built with a modular architecture:
- Core: Basic blockchain data structures and validation logic
- Consensus: Pluggable consensus mechanisms (Tendermint-style, randomness beacon)
- Network: P2P networking layer with peer discovery
- Storage: Flexible storage backends (memory, persistent, indexed)
- Crypto: Cryptographic primitives and utilities
- CLI: Command-line interface for node management
The Rust implementation uses raw UDP sockets (no libp2p) for simplicity and control:
- Bind: Each node binds a UDP socket to
host:port(port0= ephemeral). - Gossip Loop: A background task periodically rebroadcasts stored message hashes to all known peers.
- Receive Loop: Incoming datagrams are parsed as JSON
SharedMessage, deduplicated, stored, and rebroadcast. - Local Discovery: In-process nodes register in a static
LOCAL_NODESmap for automatic peer discovery within the same process. - Message Flow:
create_shared_message_with_data()stores a message, processes it throughApplicationObjects, and broadcasts to peers.
Start multiple nodes in separate terminals or use the multi-node script:
# Terminal 1
chaincraft-cli start --port 9001
# Terminal 2
chaincraft-cli start --port 9002 --peer 127.0.0.1:9001
# Terminal 3
chaincraft-cli start --port 9003 --peer 127.0.0.1:9001 --peer 127.0.0.1:9002Or run the shared objects example (in-process multi-node):
cargo run --example shared_objects_example| Python (chaincraft) | Rust (chaincraft) |
|---|---|
node.py |
src/node.rs |
SharedMessage |
shared::SharedMessage |
ApplicationObject |
shared_object::ApplicationObject |
SimpleSharedNumber |
shared_object::SimpleSharedNumber |
SimpleChainObject |
shared_object::MerkelizedChain |
| Message chain | shared_object::MessageChain |
| ECDSA ledger | examples::ecdsa_ledger::ECDSALedgerObject |
dbm / on-disk storage |
sled (feature persistent) |
local_discovery |
NodeConfig::local_discovery + LOCAL_NODES registry |
gossip loop |
Gossip task in start_networking() |
| UDP broadcast | broadcast_bytes() via UdpSocket |
compression: Enable message compression for network efficiency
persistent: Enable persistent storage using sledindexing: Enable SQLite-based transaction indexingvdf-crypto: Enable VDF (Verifiable Delay Function) support via vdf crate. Requires GMP:apt install libgmp-devorbrew install gmp
Enable features in your Cargo.toml:
[dependencies]
chaincraft = { version = "0.2.4", features = ["persistent", "indexing"] }- Rust 1.82 or later
- Git
git clone https://github.com/jose-blockchain/chaincraft-rust.git
cd chaincraft-rust
cargo build# Run all tests
cargo test
# Run tests with all features enabled
cargo test --all-features
# Run example integration tests
cargo test --test examples_integrationcargo benchcargo install cargo-tarpaulin
cargo tarpaulin --out HtmlFull API documentation is available on docs.rs.
To build documentation locally:
cargo doc --open --all-featuresCheck out the examples/ directory for more usage examples:
basic_node.rs: Simple node setup and operationkeypair_generation.rs: Cryptographic keypair generation and signingchatroom_example.rs: Decentralized chatroom protocol (create rooms, post messages)randomness_beacon_example.rs: Verifiable randomness beaconshared_objects_example.rs: Multi-node network with shared object propagationproof_of_work_example.rs: Proof of Work mining and verification
Run examples with:
cargo run --example basic_node
cargo run --example chatroom_example
cargo run --example shared_objects_exampleWe welcome contributions via pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Ensure all tests pass (
cargo test --all-features) - Run clippy (
cargo clippy --all-features) - Format your code (
cargo fmt) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Chaincraft Rust is designed for high performance:
- Zero-copy serialization where possible
- Efficient async networking with tokio
- Optimized cryptographic operations
- Configurable resource limits
Security is a top priority:
- Memory-safe Rust implementation
- Cryptographic operations use well-audited libraries
- Network protocol includes message authentication
- Input validation and sanitization throughout
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with Tokio for async runtime
- Cryptography powered by RustCrypto
- Custom UDP-based P2P networking (no libp2p dependency)
- Advanced consensus mechanisms (PBFT)
- Smart contract support
- Enhanced monitoring and metrics
- WebAssembly runtime integration
For more information, visit our documentation or repository.