Neo Rust SDK API Reference
This is the API reference for the Neo Rust SDK, providing detailed information about all modules, types, and functions available in the library.
Modules Overview
The Neo Rust SDK is organized into several modules, each focusing on a specific aspect of Neo blockchain development:
neo::prelude
The prelude module re-exports the most commonly used types, traits, and functions from the Neo Rust SDK. Importing this module with use neo3::prelude::*;
brings all essential components into scope for most applications.
use neo::prelude::*;
fn main() -> Result<()> {
let wallet = Wallet::new();
let tx_builder = TransactionBuilder::new();
let hash = Hash160::from_address("NbnjKGMBJzJ6j5PHeYhjJDaQ5Vy5UYu4Fv")?;
Ok(())
}
neo::wallet
The wallet module provides types and functions for creating, loading, and managing Neo wallets and accounts.
Wallet
The Wallet
struct represents a Neo wallet, which can contain multiple accounts.
Creates a new empty wallet.
use neo::prelude::*;
fn main() -> Result<()> {
let wallet = Wallet::new();
println!("Created new wallet");
Ok(())
}
use neo::prelude::*;
fn main() -> Result<()> {
let mut wallet = Wallet::new();
// Create a new account with a password
wallet.create_account(Some("password123"))?;
println!("Created new wallet with password-protected account");
Ok(())
}
Loads a wallet from a file, decrypting it with the provided password.
use neo::prelude::*;
fn main() -> Result<()> {
// Load wallet from file
let wallet = Wallet::load("my_wallet.json", "password123")?;
println!("Loaded wallet with {} accounts", wallet.accounts().len());
Ok(())
}
neo::transaction
The transaction module provides types and functions for building, signing, and sending Neo blockchain transactions.
TransactionBuilder
The TransactionBuilder
struct provides a fluent API for constructing Neo transactions.
Creates a new transaction builder with default values.
use neo::prelude::*;
fn main() -> Result<()> {
let tx_builder = TransactionBuilder::new();
println!("Created transaction builder");
Ok(())
}
use neo::prelude::*;
async fn create_transaction() -> Result<()> {
let wallet = Wallet::load("wallet.json", "password")?;
let account = wallet.default_account()?;
let client = NeoClient::connect_to_testnet().await?;
let block_count = client.get_block_count().await?;
let tx = TransactionBuilder::new()
.version(0)
.nonce(1234)
.valid_until_block(block_count + 100)
.sender(account.address())
.system_fee(0)
.network_fee(0)
.script(vec![0x01, 0x02, 0x03])
.sign(account)
.build();
println!("Transaction hash: {}", tx.hash());
Ok(())
}
Using the API Reference
This API reference provides detailed information about:
- Modules: The organizational structure of the SDK
- Types: Structs, enums, and type aliases
- Functions: Available methods and free functions
- Examples: Code snippets demonstrating usage
Use the navigation on the left to explore different modules and types. Each API page includes:
- Descriptions of the purpose and behavior
- Method signatures and parameters
- Return types and possible errors
- Usage examples
For more detailed examples and tutorials, refer to the Documentation and Examples sections.