Expand description
§Neo Clients
Client interfaces for interacting with Neo N3 blockchain nodes.
§Overview
The neo_clients module provides a comprehensive set of client interfaces for connecting to and interacting with Neo N3 blockchain nodes. It includes:
- RPC clients for making JSON-RPC calls to Neo nodes
- Multiple transport providers (HTTP, WebSocket, IPC)
- Subscription support for real-time blockchain events
- Mock clients for testing
- Extension traits for domain-specific functionality
- Error handling for network and protocol issues
The module is designed to be flexible, allowing developers to choose the appropriate client implementation and transport mechanism for their specific use case.
§Examples
§Connecting to a Neo N3 node using HTTP
use neo3::neo_clients::{HttpProvider, RpcClient, APITrait};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create an HTTP provider connected to a Neo N3 TestNet node
let provider = HttpProvider::new("https://testnet1.neo.org:443")?;
// Create an RPC client with the provider
let client = RpcClient::new(provider);
// Get the current block count
let block_count = client.get_block_count().await?;
println!("Current block count: {}", block_count);
// Get information about the blockchain
let version = client.get_version().await?;
println!("Node version: {}", version.user_agent);
Ok(())
}
§Using WebSocket for real-time updates
ⓘ
use neo3::neo_clients::{Ws, RpcClient, APITrait};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Connect to a Neo N3 node using WebSocket
let ws = Ws::connect("wss://testnet1.neo.org:4443/ws").await?;
let client = RpcClient::new(ws);
// Get basic blockchain information over WebSocket
let block_count = client.get_block_count().await?;
println!("Current block count: {}", block_count);
let version = client.get_version().await?;
println!("Node version: {}", version.user_agent);
Ok(())
}
Modules§
- nns
- Types for the admin api
Structs§
- Body
Regex Matcher - Cache
- High-performance cache with TTL and LRU eviction
- Cache
Config - Cache configuration
- Cache
Stats - Cache statistics
- Circuit
Breaker - Circuit breaker implementation for protecting against cascading failures
- Circuit
Breaker Config - Circuit breaker configuration
- Circuit
Breaker Stats - Circuit breaker statistics
- Claims
- Claims struct as defined in https://github.com/neo/execution-apis/blob/main/src/engine/authentication.md#jwt-claims
- Connection
Pool - High-performance connection pool for Neo RPC clients
- HTTP_
PROVIDER - Http
- A low-level JSON-RPC Client over HTTP.
- Http
Provider - A low-level JSON-RPC Client over HTTP.
- Http
Rate Limit Retry Policy - Implements RetryPolicy that will retry requests that errored with status code 429 i.e. TOO_MANY_REQUESTS
- Json
RpcError - A JSON-RPC 2.0 error
- JwtAuth
- Contains the JWT secret and claims parameters.
- JwtKey
- Generates a bearer token from a JWT secret
- Mock
Client - Params
- Pool
Config - Configuration for connection pool
- Pool
Stats - Connection pool statistics
- Production
Client Config - Configuration for production RPC client
- Production
Client Stats - Production client statistics
- Production
RpcClient - Production-ready RPC client with connection pooling, caching, and circuit breaker
- Request
- A JSON-RPC request
- Retry
Client - RetryClient presents as a wrapper around JsonRpcProvider that will retry requests based with an exponential backoff and filtering based on RetryPolicy.
- Retry
Client Builder - Builder for a
RetryClient
- RpcClient
- An abstract provider for interacting with the Neo JSON RPC
API. Must be instantiated
with a data transport which implements the
JsonRpcClient
trait (e.g. HTTP, Websockets etc.) - RwClient
- A client containing two clients.
- Subscription
Stream - Streams data from an installed filter via
neo_subscribe
Enums§
- Authorization
- Basic or bearer authentication in http or websocket transport
- Circuit
State - Circuit breaker states
- Client
Error - Error thrown when sending an HTTP request
- Http
Client Error - Error thrown when sending an HTTP request
- NeoClient
- Node Clients
- Provider
Error - An error thrown when making a call to the provider
- Response
- A JSON-RPC response
- Retry
Client Error - Error thrown when:
- RwClient
Error - Error thrown when using either read or write client
Constants§
- JWT_
SECRET_ LENGTH - JWT secret length in bytes.
Statics§
Traits§
- APITrait
- Json
RpcProvider - Trait which must be implemented by data transports to be used with the Neo JSON-RPC provider.
- Pubsub
Client - A transport implementation supporting pub sub subscriptions.
- Retry
Policy - RetryPolicy defines logic for which JsonRpcProvider::Error instances should the client retry the request and try to recover from.
Functions§
- address_
to_ hex - Convert an address to hex format.
- address_
to_ script_ hash - Convert an address to a script hash.
- hex_
to_ address - Convert a hex format script hash to an address.
- interval
- Create a stream that emits items at a fixed interval. Used for rate control
- maybe
- Calls the future if
item
is None, otherwise returns afutures::ok
- private_
key_ to_ address - Convert a private key to an address.
- private_
key_ to_ script_ hash - Convert a private key to a script hash.
- public_
key_ to_ address - Convert a public key to an address.
- public_
key_ to_ script_ hash - Convert a public key to a script hash.
- script_
hash_ from_ hex - Convert a script hash in hex format to a ScriptHash.
- script_
hash_ from_ script - Convert a script to a script hash.
- script_
hash_ to_ address - Convert a script hash to an address.
- script_
hash_ to_ hex - Convert a script hash to hex format.
- serialize
Type Aliases§
- Escalation
Policy - A simple gas escalation policy
- RpcCache
- Specialized cache for RPC responses