Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
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

Source

pub fn new() -> Self

Creates a new ClientBuilder with default configuration.

Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

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();
Source

pub fn proactive_rate_limit_sleep( self, proactive_rate_limit_sleep: bool, ) -> Self

Sets whether to proactively sleep when rate limited.

When enabled (default), the client will wait for the rate limit window to reset before sending requests it knows will be rejected. Set to false to disable this behavior and handle rate limits yourself.

§Arguments
  • proactive_rate_limit_sleep - Whether to enable proactive rate limit sleeping (default: true)
Source

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();
Source

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

Source§

fn clone(&self) -> ClientBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClientBuilder

Source§

fn default() -> ClientBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,