Module neo_clients

Source
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§

BodyRegexMatcher
Cache
High-performance cache with TTL and LRU eviction
CacheConfig
Cache configuration
CacheStats
Cache statistics
CircuitBreaker
Circuit breaker implementation for protecting against cascading failures
CircuitBreakerConfig
Circuit breaker configuration
CircuitBreakerStats
Circuit breaker statistics
Claims
Claims struct as defined in https://github.com/neo/execution-apis/blob/main/src/engine/authentication.md#jwt-claims
ConnectionPool
High-performance connection pool for Neo RPC clients
HTTP_PROVIDER
Http
A low-level JSON-RPC Client over HTTP.
HttpProvider
A low-level JSON-RPC Client over HTTP.
HttpRateLimitRetryPolicy
Implements RetryPolicy that will retry requests that errored with status code 429 i.e. TOO_MANY_REQUESTS
JsonRpcError
A JSON-RPC 2.0 error
JwtAuth
Contains the JWT secret and claims parameters.
JwtKey
Generates a bearer token from a JWT secret
MockClient
Params
PoolConfig
Configuration for connection pool
PoolStats
Connection pool statistics
ProductionClientConfig
Configuration for production RPC client
ProductionClientStats
Production client statistics
ProductionRpcClient
Production-ready RPC client with connection pooling, caching, and circuit breaker
Request
A JSON-RPC request
RetryClient
RetryClient presents as a wrapper around JsonRpcProvider that will retry requests based with an exponential backoff and filtering based on RetryPolicy.
RetryClientBuilder
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.
SubscriptionStream
Streams data from an installed filter via neo_subscribe

Enums§

Authorization
Basic or bearer authentication in http or websocket transport
CircuitState
Circuit breaker states
ClientError
Error thrown when sending an HTTP request
HttpClientError
Error thrown when sending an HTTP request
NeoClient
Node Clients
ProviderError
An error thrown when making a call to the provider
Response
A JSON-RPC response
RetryClientError
Error thrown when:
RwClientError
Error thrown when using either read or write client

Constants§

JWT_SECRET_LENGTH
JWT secret length in bytes.

Statics§

MAINNET
TESTNET

Traits§

APITrait
JsonRpcProvider
Trait which must be implemented by data transports to be used with the Neo JSON-RPC provider.
PubsubClient
A transport implementation supporting pub sub subscriptions.
RetryPolicy
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 a futures::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§

EscalationPolicy
A simple gas escalation policy
RpcCache
Specialized cache for RPC responses