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§
source§impl 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§
source§impl JsonRpcClient for Provider
impl JsonRpcClient for Provider
§type Error = ClientError
type Error = ClientError
A JSON-RPC Error
source§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,
Self: 'async_trait,
'life0: 'async_trait,
'life1: '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, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Sends a request with the provided JSON-RPC and parameters serialized as JSON