pub struct ClientBuilder(/* private fields */);Expand description
Builder for creating a hypersync client with configuration options.
This builder provides a fluent API for configuring client settings like URL, authentication, timeouts, and retry behavior.
§Example
use hypersync_client::{Client, SerializationFormat};
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.http_req_timeout_millis(30000)
.max_num_retries(3)
.build()
.unwrap();Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn chain_id(self, chain_id: u64) -> Self
pub fn chain_id(self, chain_id: u64) -> Self
Sets the chain ID and automatically configures the URL for the hypersync endpoint.
This is a convenience method that sets the URL to https://{chain_id}.hypersync.xyz.
§Arguments
chain_id- The blockchain chain ID (e.g., 1 for Ethereum mainnet)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1) // Ethereum mainnet
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.build()
.unwrap();Sourcepub fn url<S: ToString>(self, url: S) -> Self
pub fn url<S: ToString>(self, url: S) -> Self
Sets a custom URL for the hypersync server.
Use this method when you need to connect to a custom hypersync endpoint instead of the default public endpoints.
§Arguments
url- The hypersync server URL
§Example
use hypersync_client::Client;
let client = Client::builder()
.url("https://my-custom-hypersync.example.com")
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.build()
.unwrap();Sourcepub fn api_token<S: ToString>(self, api_token: S) -> Self
pub fn api_token<S: ToString>(self, api_token: S) -> Self
Sets the api token for authentication.
Required for accessing authenticated hypersync endpoints.
§Arguments
api_token- The authentication token
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.build()
.unwrap();Sourcepub fn http_req_timeout_millis(self, http_req_timeout_millis: u64) -> Self
pub fn http_req_timeout_millis(self, http_req_timeout_millis: u64) -> Self
Sets the HTTP request timeout in milliseconds.
§Arguments
http_req_timeout_millis- Timeout in milliseconds (default: 30000)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.http_req_timeout_millis(60000) // 60 second timeout
.build()
.unwrap();Sourcepub fn max_num_retries(self, max_num_retries: usize) -> Self
pub fn max_num_retries(self, max_num_retries: usize) -> Self
Sets the maximum number of retries for failed requests.
§Arguments
max_num_retries- Maximum number of retries (default: 10)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.max_num_retries(5)
.build()
.unwrap();Sourcepub fn retry_backoff_ms(self, retry_backoff_ms: u64) -> Self
pub fn retry_backoff_ms(self, retry_backoff_ms: u64) -> Self
Sets the backoff increment for retry delays.
This value is added to the base delay on each retry attempt.
§Arguments
retry_backoff_ms- Backoff increment in milliseconds (default: 500)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.retry_backoff_ms(1000) // 1 second backoff increment
.build()
.unwrap();Sourcepub fn retry_base_ms(self, retry_base_ms: u64) -> Self
pub fn retry_base_ms(self, retry_base_ms: u64) -> Self
Sets the initial delay for retry attempts.
§Arguments
retry_base_ms- Initial retry delay in milliseconds (default: 500)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.retry_base_ms(1000) // Start with 1 second delay
.build()
.unwrap();Sourcepub fn retry_ceiling_ms(self, retry_ceiling_ms: u64) -> Self
pub fn retry_ceiling_ms(self, retry_ceiling_ms: u64) -> Self
Sets the maximum delay for retry attempts.
The retry delay will not exceed this value, even with backoff increments.
§Arguments
retry_ceiling_ms- Maximum retry delay in milliseconds (default: 10000)
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.retry_ceiling_ms(30000) // Cap at 30 seconds
.build()
.unwrap();Sourcepub fn serialization_format(
self,
serialization_format: SerializationFormat,
) -> Self
pub fn serialization_format( self, serialization_format: SerializationFormat, ) -> Self
Sets the serialization format for client-server communication.
§Arguments
serialization_format- The format to use (JSON or CapnProto)
§Example
use hypersync_client::{Client, SerializationFormat};
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.serialization_format(SerializationFormat::Json)
.build()
.unwrap();Sourcepub fn build(self) -> Result<Client>
pub fn build(self) -> Result<Client>
Builds the client with the configured settings.
§Returns
Result<Client>- The configured client or an error if configuration is invalid
§Errors
Returns an error if:
- The URL is malformed
- Required configuration is missing
§Example
use hypersync_client::Client;
let client = Client::builder()
.chain_id(1)
.api_token(std::env::var("ENVIO_API_TOKEN").unwrap())
.build()
.unwrap();Trait Implementations§
Source§impl Clone for ClientBuilder
impl Clone for ClientBuilder
Source§fn clone(&self) -> ClientBuilder
fn clone(&self) -> ClientBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientBuilder
impl Debug for ClientBuilder
Source§impl Default for ClientBuilder
impl Default for ClientBuilder
Source§fn default() -> ClientBuilder
fn default() -> ClientBuilder
Auto Trait Implementations§
impl Freeze for ClientBuilder
impl RefUnwindSafe for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnwindSafe for ClientBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more