| Crates.io | neo3 |
| lib.rs | neo3 |
| version | 1.0.1 |
| created_at | 2025-02-28 20:49:56.371597+00 |
| updated_at | 2026-01-20 09:38:03.802445+00 |
| description | Production-ready Rust SDK for Neo N3 blockchain with high-level API, unified error handling, and enterprise features |
| homepage | https://github.com/R3E-Network/NeoRust |
| repository | https://github.com/R3E-Network/NeoRust |
| max_upload_size | |
| id | 1573166 |
| size | 7,682,297 |
A comprehensive, production-ready Rust SDK for the Neo N3 blockchain platform. NeoRust provides an enterprise-grade toolkit with simplified APIs, real-time features, and professional developer tools for building blockchain applications.
Add NeoRust to your Cargo.toml:
[dependencies]
neo3 = "1.0.1"
use neo3::sdk::{Neo, Network};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Quick connection to TestNet
let neo = Neo::testnet().await?;
// Get balance with automatic error handling
let balance = neo.get_balance("NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc").await?;
println!("Balance: {} NEO, {} GAS", balance.neo, balance.gas);
// Custom configuration with all features
let neo = Neo::builder()
.network(Network::MainNet)
.timeout(Duration::from_secs(30))
.retries(3)
.cache(true)
.build()
.await?;
Ok(())
}
use neo3::neo_clients::{HttpProvider, RpcClient};
// 1) HTTP (default, no extra feature flags)
let http = HttpProvider::new("https://testnet1.neo.org:443")?;
let client = RpcClient::new(http);
// 2) Modern WebSocket client (enable the `ws` feature)
#[cfg(feature = "ws")]
{
use neo3::neo_clients::rpc::transports::Ws;
let ws = Ws::connect("wss://testnet1.neo.org:443/ws").await?;
let client = RpcClient::new(ws);
}
// 3) IPC (enable the `ipc` feature)
#[cfg(feature = "ipc")]
{
use neo3::neo_clients::rpc::transports::Ipc;
let ipc = Ipc::connect("/tmp/neo.ipc").await?;
let client = RpcClient::new(ipc);
}
// 4) Offline-friendly mock (enable the `mock` feature; great for tests/CI)
#[cfg(feature = "mock")]
{
use neo3::neo_clients::MockClient;
let mut mock = MockClient::new().await;
mock.mock_get_block_count(1_000).await;
mock.mount_mocks().await;
let client = mock.into_client();
}
ws: enable the modern WebSocket transportipc: enable IPC (Unix domain sockets / Windows named pipes)legacy-ws: legacy WebSocket compatibility layer (fallback)mock: enable MockClient and in-memory mocking helpersledger, yubi: opt into hardware wallet supportno_std, sgx: specialized environmentsRequires the ws feature:
neo3 = { version = "1.0.1", features = ["ws"] }
use neo3::sdk::websocket::{WebSocketClient, SubscriptionType};
// Connect to WebSocket
let mut ws = WebSocketClient::new("ws://localhost:10332/ws").await?;
ws.connect().await?;
// Subscribe to new blocks
let handle = ws.subscribe(SubscriptionType::NewBlocks).await?;
// Process events
if let Some(mut rx) = ws.take_event_receiver() {
while let Some((sub_type, event)) = rx.recv().await {
println!("New event: {:?}", event);
}
}
use neo3::sdk::hd_wallet::HDWallet;
// Generate new HD wallet with 24-word mnemonic
let wallet = HDWallet::generate(24, None)?;
println!("Mnemonic: {}", wallet.mnemonic_phrase());
// Derive multiple accounts
let mut wallet = wallet;
let account1 = wallet.derive_account("m/44'/888'/0'/0/0")?;
let account2 = wallet.derive_account("m/44'/888'/0'/0/1")?;
// Import from existing mnemonic
let wallet = HDWallet::from_phrase(
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
None,
Language::English
)?;
use neo3::sdk::transaction_simulator::TransactionSimulator;
// Create simulator
let mut simulator = TransactionSimulator::new(client);
// Simulate before sending
let result = simulator.simulate_script(&script, signers).await?;
if result.success {
println!("Estimated gas: {} GAS", result.gas_consumed as f64 / 100_000_000.0);
println!("State changes: {:?}", result.state_changes);
// Check for warnings
for warning in result.warnings {
println!("⚠️ {}", warning.message);
}
// Get optimization suggestions
for suggestion in result.suggestions {
println!("💡 {}", suggestion.description);
}
} else {
println!("Transaction would fail: {:?}", result.vm_state);
}
use neo3::neo_clients::{APITrait, HttpProvider, RpcClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Neo TestNet
let provider = HttpProvider::new("https://testnet1.neo.coz.io:443")?;
let client = RpcClient::new(provider);
// Query basic chain state (works without a wallet)
let block_count = client.get_block_count().await?;
println!("Block height: {}", block_count.saturating_sub(1));
Ok(())
}
neo3)The main Rust SDK providing all blockchain functionality.
neo-cli)Interactive command-line interface with wizard mode:
# Launch interactive wizard
neo-cli wizard
# Generate a new project from template
neo-cli generate --template nep17-token my-token
# Common commands
neo-cli wallet create --path my-wallet.json
neo-cli network connect --network testnet
neo-cli network status
neo-cli de-fi token NEO
cargo build --workspace
Explore our comprehensive examples:
NEO_RPC_URL to point examples at your preferred node; otherwise they run offline-friendly paths.See the examples directory for full code samples.
Licensed under MIT license (LICENSE or http://opensource.org/licenses/MIT)
# Run all tests
cargo test --workspace
# Run specific component tests
cargo test -p neo3
cargo test -p neo-cli
# Run integration tests
cargo test --test integration_tests
The project uses streamlined GitHub Actions workflows:
build-test.yml - Unified build, test, and quality checks
release.yml - Automated release process
# Format check
cargo fmt --all -- --check
# Clippy lints
cargo clippy --all-targets --all-features -- -D warnings
# Run all tests
cargo test --all-features
# Security audit
cargo audit
# Build documentation
cargo doc --no-deps --all-features
| Feature | Pre-1.0 | v1.0.x | Improvement |
|---|---|---|---|
| Connection Setup | 5-10 lines | 1 line | 90% reduction |
| Balance Check | Manual RPC + parsing | Single method | 70% reduction |
| Error Handling | Basic errors | Recovery suggestions | Enhanced UX |
| Real-time Events | Not supported | WebSocket with auto-reconnect | New feature |
| HD Wallets | Not supported | BIP-39/44 compliant | New feature |
| Gas Estimation | Manual calculation | Automatic simulation | 95% accuracy |
| Transaction Preview | Not available | Full state change preview | New feature |
| Project Setup | Manual | Template generation | 80% faster |
| CLI Experience | Commands only | Interactive wizard | Enhanced UX |
// Pre-1.0
let provider = HttpProvider::new("https://testnet1.neo.org:443")?;
let client = RpcClient::new(provider);
let result = client.invoke_function(&contract, "balanceOf", vec![address], None).await?;
let balance = parse_balance(result)?; // Manual parsing
// v1.0
let neo = Neo::testnet().await?;
let balance = neo.get_balance(address).await?; // Automatic parsing
NeoError with recovery suggestionsSee the full migration guide for detailed instructions.
| Operation | Pre-1.0 | v1.0.x | Improvement |
|---|---|---|---|
| WebSocket Events | N/A | <100ms | New |
| HD Account Derivation | N/A | <10ms | New |
| Transaction Simulation | N/A | <200ms | New |
| Balance Query | 300-500ms | 200-300ms | 40% faster |
| Token Transfer | 15-20 lines | 5-7 lines | 65% less code |
| Error Recovery | Manual | Automatic suggestions | Enhanced |
Contributions are welcome! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)Please ensure:
cargo test --workspace)cargo fmt)cargo clippy -- -D warnings)For security issues, please email security@r3e.network instead of using the issue tracker.