Struct ethers_providers::Http
source · [−]pub struct Http { /* private fields */ }Expand description
A low-level JSON-RPC Client over HTTP.
Example
use ethers_core::types::U64;
use ethers_providers::{JsonRpcClient, Http};
use std::str::FromStr;
let provider = Http::from_str("http://localhost:8545")?;
let block_number: U64 = provider.request("eth_blockNumber", ()).await?;Implementations
sourceimpl Provider
impl Provider
sourcepub fn new(url: impl Into<Url>) -> Self
pub fn new(url: impl Into<Url>) -> Self
Initializes a new HTTP Client
Example
use ethers_providers::Http;
use url::Url;
let url = Url::parse("http://localhost:8545").unwrap();
let provider = Http::new(url);sourcepub fn new_with_auth(
url: impl Into<Url>,
auth: Authorization
) -> Result<Self, HttpClientError>
pub fn new_with_auth(
url: impl Into<Url>,
auth: Authorization
) -> Result<Self, HttpClientError>
Initializes a new HTTP Client with authentication
Example
use ethers_providers::{Authorization, Http};
use url::Url;
let url = Url::parse("http://localhost:8545").unwrap();
let provider = Http::new_with_auth(url, Authorization::basic("admin", "good_password"));sourcepub fn new_with_client(url: impl Into<Url>, client: Client) -> Self
pub fn new_with_client(url: impl Into<Url>, client: Client) -> Self
Allows to customize the provider by providing your own http client
Example
use ethers_providers::Http;
use url::Url;
let url = Url::parse("http://localhost:8545").unwrap();
let client = reqwest::Client::builder().build().unwrap();
let provider = Http::new_with_client(url, client);Trait Implementations
sourceimpl JsonRpcClient for Provider
impl JsonRpcClient for Provider
sourcefn request<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T
) -> Pin<Box<dyn Future<Output = Result<R, ClientError>> + Send + 'async_trait>> where
T: 'async_trait + Serialize + Send + Sync,
R: 'async_trait + DeserializeOwned,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn request<'life0, 'life1, 'async_trait, T, R>(
&'life0 self,
method: &'life1 str,
params: T
) -> Pin<Box<dyn Future<Output = Result<R, ClientError>> + Send + 'async_trait>> where
T: 'async_trait + Serialize + Send + Sync,
R: 'async_trait + DeserializeOwned,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sends a POST request with the provided method and the params serialized as JSON over HTTP
type Error = ClientError
type Error = ClientError
A JSON-RPC Error
Auto Trait Implementations
impl !RefUnwindSafe for Provider
impl Send for Provider
impl Sync for Provider
impl Unpin for Provider
impl !UnwindSafe for Provider
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more