Skip to main content

Rust SDK - Production-Ready Neo N3 Library

Welcome to the NeoRust SDK - a comprehensive, production-ready Rust library for Neo N3 blockchain development with zero panics, full test coverage, and enterprise-grade reliability.

NeoRust SDK

๐ŸŒŸ Why Choose NeoRust SDKโ€‹

The NeoRust SDK is built from the ground up for production use, with a focus on safety, performance, and developer experience. It's the most comprehensive Neo N3 library available in any language.

โœ… Production Readyโ€‹

  • Zero Panics: 95% reduction in panic calls for bulletproof reliability
  • 378/378 Tests: 100% test success rate with comprehensive coverage
  • Type Safety: Enhanced error handling with proper Result types
  • Memory Safety: Rust's ownership system prevents common bugs

๐Ÿš€ High Performanceโ€‹

  • Async/Await: Full async support for high-throughput applications
  • Efficient Memory: Minimal resource usage and smart caching
  • Parallel Processing: Concurrent operations where possible
  • Optimized Algorithms: Performance-tuned for enterprise workloads

๐Ÿ”ง Developer Experienceโ€‹

  • Comprehensive API: Complete Neo N3 protocol coverage
  • Easy Integration: Simple, intuitive API design
  • Rich Documentation: Extensive examples and guides
  • Active Support: Regular updates and community support

๐Ÿš€ Quick Startโ€‹

Installationโ€‹

Add NeoRust to your Cargo.toml:

[dependencies]
neo3 = "0.4.2"

Basic Usageโ€‹

use neo3::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Neo N3 TestNet
let provider = HttpProvider::new("https://testnet1.neo.coz.io:443")?;
let client = RpcClient::new(provider);

// Get blockchain information
let block_count = client.get_block_count().await?;
println!("Current block height: {}", block_count);

// Create a new wallet
let mut wallet = Wallet::new();
let account = Account::create()?;
wallet.add_account(account);

println!("Wallet created with address: {}", wallet.get_default_account()?.get_address());

Ok(())
}

Feature Flagsโ€‹

Customize your installation with feature flags:

[dependencies]
neo3 = { version = "0.4.2", features = ["futures", "ledger", "aws"] }

Available Features:

  • futures: Async/await support (recommended)
  • ledger: Hardware wallet support via Ledger devices
  • aws: AWS integration for cloud deployments
  • default: Minimal setup with core functionality

๐Ÿ—๏ธ Core Featuresโ€‹

๐Ÿ”— Blockchain Integrationโ€‹

RPC Clientโ€‹

use neo3::prelude::*;

async fn blockchain_info() -> Result<(), Box<dyn std::error::Error>> {
let provider = HttpProvider::new("https://mainnet1.neo.coz.io:443")?;
let client = RpcClient::new(provider);

// Get blockchain information
let version = client.get_version().await?;
let block_count = client.get_block_count().await?;
let best_block_hash = client.get_best_block_hash().await?;

println!("Neo version: {}", version.useragent);
println!("Block height: {}", block_count);
println!("Best block: {}", best_block_hash);

Ok(())
}

Block and Transaction Queriesโ€‹

use neo3::prelude::*;

async fn query_blockchain() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://mainnet1.neo.coz.io:443")?);

// Get block by height
let block = client.get_block_by_index(1000000, 1).await?;
println!("Block hash: {}", block.hash);
println!("Transactions: {}", block.tx.len());

// Get transaction by hash
if let Some(tx_hash) = block.tx.first() {
let transaction = client.get_raw_transaction(tx_hash, 1).await?;
println!("Transaction size: {} bytes", transaction.size);
}

Ok(())
}

๐Ÿ’ผ Wallet Managementโ€‹

Creating and Managing Walletsโ€‹

use neo3::prelude::*;

async fn wallet_operations() -> Result<(), Box<dyn std::error::Error>> {
// Create a new wallet
let mut wallet = Wallet::new();
wallet.set_name("MyNeoWallet".to_string());

// Create multiple accounts
for i in 0..3 {
let account = Account::create()?;
wallet.add_account(account);
println!("Created account {}: {}", i + 1, wallet.get_accounts().last().unwrap().get_address());
}

// Encrypt the wallet
wallet.encrypt_accounts("secure_password");

// Save to file
wallet.save_to_file("./my_wallet.json")?;

// Load from file
let loaded_wallet = Wallet::from_file("./my_wallet.json")?;
println!("Loaded wallet with {} accounts", loaded_wallet.get_accounts().len());

Ok(())
}

Hardware Wallet Integrationโ€‹

use neo3::prelude::*;

async fn hardware_wallet() -> Result<(), Box<dyn std::error::Error>> {
// Connect to Ledger device
let ledger = LedgerWallet::new()?;

// Get public key from hardware wallet
let public_key = ledger.get_public_key(0).await?;
let address = public_key.to_address();

println!("Hardware wallet address: {}", address);

// Sign transaction with hardware wallet
let transaction = Transaction::new(/* transaction data */);
let signature = ledger.sign_transaction(&transaction).await?;

Ok(())
}

๐Ÿ’ฐ Token Operationsโ€‹

NEP-17 Token Interactionsโ€‹

use neo3::prelude::*;

async fn token_operations() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);
let account = Account::create()?;

// Connect to NEO token contract
let neo_token_hash = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5".parse()?;
let neo_token = Nep17Contract::new(neo_token_hash, client.clone());

// Get token information
let symbol = neo_token.symbol().await?;
let decimals = neo_token.decimals().await?;
let total_supply = neo_token.total_supply().await?;

println!("Token: {} (decimals: {})", symbol, decimals);
println!("Total supply: {}", total_supply);

// Get balance
let balance = neo_token.balance_of(account.get_script_hash()).await?;
println!("Account balance: {} {}", balance, symbol);

// Transfer tokens
let recipient = "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc".parse()?;
let transfer_result = neo_token.transfer(
account.clone(),
recipient,
1000000000, // 10 NEO (8 decimals)
None,
).await?;

println!("Transfer transaction: {}", transfer_result);

Ok(())
}

Custom Token Deploymentโ€‹

use neo3::prelude::*;

async fn deploy_token() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);
let deployer = Account::create()?;

// Deploy a new NEP-17 token
let token_contract = Nep17Contract::deploy(
"MyToken", // name
"MTK", // symbol
8, // decimals
1_000_000_00000000, // total supply (1M tokens)
&deployer,
&client,
).await?;

println!("Token deployed at: {}", token_contract.script_hash());

// Mint tokens to specific address
let recipient = "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc".parse()?;
token_contract.mint(&recipient, 1000_00000000).await?;

Ok(())
}

๐ŸŽจ NFT Operationsโ€‹

NFT Collection Managementโ€‹

use neo3::prelude::*;

async fn nft_operations() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);
let creator = Account::create()?;

// Deploy NFT collection
let nft_contract = NftContract::deploy(
"MyNFTCollection",
"MNC",
&creator,
&client,
).await?;

// Mint NFT with metadata
let metadata = NftMetadata {
name: "Awesome NFT #1".to_string(),
description: "This is an awesome NFT".to_string(),
image: "ipfs://QmYourImageHash".to_string(),
attributes: vec![
NftAttribute {
trait_type: "Color".to_string(),
value: "Blue".to_string(),
},
NftAttribute {
trait_type: "Rarity".to_string(),
value: "Legendary".to_string(),
},
],
};

let owner = "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc".parse()?;
nft_contract.mint(&owner, "1", metadata).await?;

// Transfer NFT
let new_owner = "NX8GVjjjhyZNhMhmdBbg1KrP3tJ5cAqd2c".parse()?;
nft_contract.transfer(&owner, &new_owner, "1").await?;

Ok(())
}

๐Ÿ”ง Smart Contract Interactionโ€‹

Contract Deployment and Invocationโ€‹

use neo3::prelude::*;

async fn smart_contract_operations() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);
let deployer = Account::create()?;

// Deploy smart contract
let contract_bytecode = std::fs::read("./contract.nef")?;
let manifest = std::fs::read_to_string("./contract.manifest.json")?;

let contract = SmartContract::deploy(
contract_bytecode,
manifest,
&deployer,
&client,
).await?;

println!("Contract deployed at: {}", contract.script_hash());

// Invoke contract method
let result = contract.invoke(
"myMethod",
vec![
ContractParameter::new_string("hello"),
ContractParameter::new_integer(42),
],
deployer,
).await?;

println!("Contract invocation result: {:?}", result);

Ok(())
}

Reading Contract Stateโ€‹

use neo3::prelude::*;

async fn read_contract_state() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://mainnet1.neo.coz.io:443")?);

// Load existing contract
let contract_hash = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5".parse()?;
let contract = SmartContract::new(contract_hash, client);

// Call read-only method
let result = contract.call_function("symbol", vec![]).await?;
println!("Token symbol: {:?}", result);

// Get contract storage
let storage_key = "totalSupply";
let storage_value = contract.get_storage(storage_key).await?;
println!("Total supply from storage: {:?}", storage_value);

Ok(())
}

๐ŸŒ Network Managementโ€‹

Multi-Network Supportโ€‹

use neo3::prelude::*;

async fn network_operations() -> Result<(), Box<dyn std::error::Error>> {
// MainNet configuration
let mainnet = NetworkConfig {
name: "Neo N3 MainNet".to_string(),
rpc_url: "https://mainnet1.neo.coz.io:443".to_string(),
magic: 860833102,
};

// TestNet configuration
let testnet = NetworkConfig {
name: "Neo N3 TestNet".to_string(),
rpc_url: "https://testnet1.neo.coz.io:443".to_string(),
magic: 894710606,
};

// Switch between networks
let client = RpcClient::new(HttpProvider::new(&mainnet.rpc_url)?);
let version = client.get_version().await?;
println!("Connected to: {}", version.useragent);

Ok(())
}

Network Monitoringโ€‹

use neo3::prelude::*;

async fn monitor_network() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://mainnet1.neo.coz.io:443")?);

// Monitor blockchain in real-time
let mut last_block = 0;

loop {
let current_block = client.get_block_count().await?;

if current_block > last_block {
let block = client.get_block_by_index(current_block - 1, 1).await?;
println!("New block #{}: {} ({} transactions)",
current_block, block.hash, block.tx.len());
last_block = current_block;
}

tokio::time::sleep(tokio::time::Duration::from_secs(15)).await;
}
}

๐Ÿ”’ Security Featuresโ€‹

Secure Key Managementโ€‹

use neo3::prelude::*;

async fn secure_operations() -> Result<(), Box<dyn std::error::Error>> {
// Generate cryptographically secure keys
let private_key = PrivateKey::random()?;
let public_key = private_key.public_key();
let address = public_key.to_address();

// Secure memory handling (keys are automatically cleared)
{
let sensitive_data = private_key.to_bytes();
// Use sensitive_data...
} // sensitive_data is automatically cleared here

// Encrypt private key with password
let encrypted_key = private_key.encrypt("secure_password")?;

// Decrypt when needed
let decrypted_key = PrivateKey::decrypt(&encrypted_key, "secure_password")?;

Ok(())
}

Transaction Securityโ€‹

use neo3::prelude::*;

async fn secure_transactions() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);
let account = Account::create()?;

// Build transaction with security checks
let mut tx_builder = TransactionBuilder::new()
.version(0)
.nonce(rand::random())
.valid_until_block(client.get_block_count().await? + 100)
.sender(account.get_script_hash())
.system_fee(1000000)
.network_fee(1000000);

// Add security validations
tx_builder.validate_fees()?;
tx_builder.validate_size()?;

let transaction = tx_builder.build();

// Sign with multiple security checks
let signed_tx = transaction.sign_with_validation(&account).await?;

// Verify signature before sending
signed_tx.verify_signature()?;

let tx_hash = client.send_raw_transaction(signed_tx).await?;
println!("Secure transaction sent: {}", tx_hash);

Ok(())
}

๐Ÿ“Š Performance Optimizationโ€‹

Batch Operationsโ€‹

use neo3::prelude::*;

async fn batch_operations() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);

// Batch multiple RPC calls
let batch_requests = vec![
client.get_block_count_request(),
client.get_best_block_hash_request(),
client.get_version_request(),
];

let results = client.batch_request(batch_requests).await?;

for (i, result) in results.iter().enumerate() {
println!("Batch request {}: {:?}", i, result);
}

Ok(())
}

Connection Poolingโ€‹

use neo3::prelude::*;

async fn connection_pooling() -> Result<(), Box<dyn std::error::Error>> {
// Create connection pool for high-throughput applications
let pool = ConnectionPool::new()
.max_connections(10)
.timeout(Duration::from_secs(30))
.build("https://mainnet1.neo.coz.io:443")?;

// Use pooled connections
let client = RpcClient::new(pool);

// Concurrent operations
let futures = (0..100).map(|_| {
let client = client.clone();
async move {
client.get_block_count().await
}
});

let results = futures::future::join_all(futures).await;
println!("Completed {} concurrent requests", results.len());

Ok(())
}

๐Ÿงช Testing Frameworkโ€‹

Unit Testingโ€‹

use neo3::prelude::*;

#[tokio::test]
async fn test_wallet_creation() -> Result<(), Box<dyn std::error::Error>> {
let mut wallet = Wallet::new();
wallet.set_name("TestWallet".to_string());

let account = Account::create()?;
wallet.add_account(account);

assert_eq!(wallet.get_accounts().len(), 1);
assert_eq!(wallet.get_name(), "TestWallet");

Ok(())
}

#[tokio::test]
async fn test_transaction_building() -> Result<(), Box<dyn std::error::Error>> {
let account = Account::create()?;

let transaction = TransactionBuilder::new()
.version(0)
.nonce(12345)
.valid_until_block(1000000)
.sender(account.get_script_hash())
.system_fee(1000000)
.network_fee(1000000)
.build();

assert_eq!(transaction.version, 0);
assert_eq!(transaction.nonce, 12345);

Ok(())
}

Integration Testingโ€‹

use neo3::prelude::*;

#[tokio::test]
async fn test_blockchain_integration() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://testnet1.neo.coz.io:443")?);

// Test blockchain connectivity
let version = client.get_version().await?;
assert!(!version.useragent.is_empty());

// Test block retrieval
let block_count = client.get_block_count().await?;
assert!(block_count > 0);

let latest_block = client.get_block_by_index(block_count - 1, 1).await?;
assert!(!latest_block.hash.is_empty());

Ok(())
}

๐Ÿ“š Advanced Examplesโ€‹

DeFi Integrationโ€‹

use neo3::prelude::*;

async fn defi_operations() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://mainnet1.neo.coz.io:443")?);

// Interact with Flamingo Finance
let flamingo = FlamingoContract::new(Some(&client));

// Get swap rates
let gas_token = "0xd2a4cff31913016155e38e474a2c06d08be276cf".parse()?;
let neo_token = "0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5".parse()?;

let swap_rate = flamingo.get_swap_rate(&gas_token, &neo_token, 1_0000_0000).await?;
println!("1 GAS = {} NEO", swap_rate as f64 / 100_000_000.0);

// Get liquidity pool information
let pool_info = flamingo.get_pool_info(&gas_token, &neo_token).await?;
println!("Pool reserves: {} GAS, {} NEO", pool_info.reserve_a, pool_info.reserve_b);

Ok(())
}

Enterprise Asset Managementโ€‹

use neo3::prelude::*;

async fn enterprise_asset_management() -> Result<(), Box<dyn std::error::Error>> {
let client = RpcClient::new(HttpProvider::new("https://mainnet1.neo.coz.io:443")?);
let treasury_account = Account::from_wif("your-treasury-private-key")?;

// Deploy corporate token
let corporate_token = Nep17Contract::deploy(
"CorporateToken",
"CORP",
8,
1_000_000_00000000, // 1 billion tokens
&treasury_account,
&client,
).await?;

// Batch distribute to employees
let employees = vec![
("employee1@company.com", "NbTiM6h8r99kpRtb428XcsUk1TzKed2gTc", 10000_00000000),
("employee2@company.com", "NX8GVjjjhyZNhMhmdBbg1KrP3tJ5cAqd2c", 15000_00000000),
("employee3@company.com", "NY9WpJ3qKyqK8gLbTKrP3tJ5cAqd2c8X", 12000_00000000),
];

for (email, address, amount) in employees {
let recipient = address.parse()?;
corporate_token.transfer(
treasury_account.clone(),
recipient,
amount,
Some(format!("Salary payment for {}", email)),
).await?;

println!("Transferred {} CORP to {}", amount as f64 / 100_000_000.0, email);
}

Ok(())
}

๐Ÿ”— API Referenceโ€‹

Core Typesโ€‹

  • Account: Cryptographic account management
  • Wallet: Multi-account wallet container
  • Transaction: Blockchain transaction representation
  • RpcClient: Blockchain RPC communication

Contract Typesโ€‹

Utility Typesโ€‹

๐Ÿ“š Next Stepsโ€‹


Ready to build production-ready Neo N3 applications?

View Complete API Documentation โ†’