diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 24f5e4ca..b522f980 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -173,9 +173,7 @@ documentation test: /// use ethers::providers::{JsonRpcClient, Provider, Http}; /// use std::convert::TryFrom; /// -/// let provider = Provider::::try_from( -/// "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" -/// ).expect("could not instantiate HTTP Provider"); +/// let provider = Provider::::try_from("https://eth.llamarpc.com").expect("could not instantiate HTTP Provider"); /// /// # async fn foo(provider: &Provider

) -> Result<(), Box> { /// let block = provider.get_block(100u64).await?; diff --git a/book/getting-started/connect_to_an_ethereum_node.md b/book/getting-started/connect_to_an_ethereum_node.md index dec2e334..d9598839 100644 --- a/book/getting-started/connect_to_an_ethereum_node.md +++ b/book/getting-started/connect_to_an_ethereum_node.md @@ -4,28 +4,28 @@ Ethers-rs allows application to connect the blockchain using web3 providers. Pro Some common actions you can perform using a provider include: -* Getting the current block number -* Getting the balance of an Ethereum address -* Sending a transaction to the blockchain -* Calling a smart contract function -* Subscribe logs and smart contract events -* Getting the transaction history of an address +- Getting the current block number +- Getting the balance of an Ethereum address +- Sending a transaction to the blockchain +- Calling a smart contract function +- Subscribe logs and smart contract events +- Getting the transaction history of an address Providers are an important part of web3 libraries because they allow you to easily interact with the Ethereum blockchain without having to manage the underlying connection to the node yourself. Code below shows a basic setup to connect a provider to a node: ```rust -// The `prelude` module provides a convenient way to import a number -// of common dependencies at once. This can be useful if you are working -// with multiple parts of the library and want to avoid having +// The `prelude` module provides a convenient way to import a number +// of common dependencies at once. This can be useful if you are working +// with multiple parts of the library and want to avoid having // to import each dependency individually. use ethers::prelude::*; -const RPC_URL: &str = "https://mainnet.infura.io/v3/your-project-id"; +const RPC_URL: &str = "https://eth.llamarpc.com"; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<(), Box> { let provider = Provider::::try_from(RPC_URL)?; let block_number: U64 = provider.get_block_number().await?; println!("{block_number}"); diff --git a/book/providers/advanced_usage.md b/book/providers/advanced_usage.md index 28916a6a..47a7b1dc 100644 --- a/book/providers/advanced_usage.md +++ b/book/providers/advanced_usage.md @@ -16,7 +16,7 @@ use std::sync::Arc; #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider: Arc> = Arc::new(Provider::::try_from(rpc_url)?); let from_adr: H160 = "0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse()?; @@ -50,7 +50,7 @@ use std::sync::Arc; #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider: Arc> = Arc::new(Provider::::try_from(rpc_url)?); let from_adr: H160 = "0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse()?; @@ -85,7 +85,7 @@ use std::sync::Arc; #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider: Arc> = Arc::new(Provider::::try_from(rpc_url)?); let from_adr: H160 = "0x6fC21092DA55B392b045eD78F4732bff3C580e2c".parse()?; diff --git a/book/providers/http.md b/book/providers/http.md index 1c119577..8f274657 100644 --- a/book/providers/http.md +++ b/book/providers/http.md @@ -12,7 +12,7 @@ use ethers::providers::{Http, Middleware, Provider}; #[tokio::main] async fn main() -> eyre::Result<()> { // Initialize a new Http provider - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider = Provider::try_from(rpc_url)?; Ok(()) @@ -60,7 +60,7 @@ use ethers::providers::{Http, Middleware, Provider}; #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider = Provider::try_from(rpc_url)?; let chain_id = provider.get_chainid().await?; @@ -88,7 +88,7 @@ abigen!( #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider = Arc::new(Provider::try_from(rpc_url)?); // Initialize a new instance of the Weth/Dai Uniswap V2 pair contract @@ -108,13 +108,12 @@ This example is a little more complicated, so let's walk through what is going o It is very common to wrap a provider in an `Arc` to share the provider across threads. Let's look at another example where the provider is used asynchronously across two tokio threads. In the next example, a new provider is initialized and used to asynchronously fetch the number of Ommer blocks from the most recent block, as well as the previous block. ```rust -use std::sync::Arc; - use ethers::providers::{Http, Middleware, Provider}; +use std::sync::Arc; #[tokio::main] async fn main() -> eyre::Result<()> { - let rpc_url = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let rpc_url = "https://eth.llamarpc.com"; let provider = Arc::new(Provider::try_from(rpc_url)?); let current_block_number = provider.get_block_number().await?; diff --git a/ethers-contract/src/multicall/mod.rs b/ethers-contract/src/multicall/mod.rs index 14f7cd55..7c101131 100644 --- a/ethers-contract/src/multicall/mod.rs +++ b/ethers-contract/src/multicall/mod.rs @@ -134,7 +134,7 @@ impl MulticallVersion { /// let abi: Abi = serde_json::from_str(r#"[{"inputs":[{"internalType":"string","name":"value","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"author","type":"address"},{"indexed":true,"internalType":"address","name":"oldAuthor","type":"address"},{"indexed":false,"internalType":"string","name":"oldValue","type":"string"},{"indexed":false,"internalType":"string","name":"newValue","type":"string"}],"name":"ValueChanged","type":"event"},{"inputs":[],"name":"getValue","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"value","type":"string"}],"name":"setValue","outputs":[],"stateMutability":"nonpayable","type":"function"}]"#)?; /// /// // connect to the network -/// let client = Provider::::try_from("https://goerli.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27")?; +/// let client = Provider::::try_from("http://localhost:8545")?; /// /// // create the contract object. This will be used to construct the calls for multicall /// let client = Arc::new(client); diff --git a/ethers-providers/README.md b/ethers-providers/README.md index 820eeb83..557fb9bf 100644 --- a/ethers-providers/README.md +++ b/ethers-providers/README.md @@ -43,15 +43,7 @@ and can be overriden with the [`ens`](./struct.Provider.html#method.ens) method # use ethers_core::types::Address; # use ethers_providers::{Provider, Http, Middleware, Ws}; # async fn foo() -> Result<(), Box> { -// HTTP Provider -let provider = Provider::::try_from( - "https://mainnet.infura.io/v3/YOUR_API_KEY" -)?; - -// Websocket Provider -let provider = Provider::::connect( - "wss://mainnet.infura.io/v3/YOUR_API_KEY" -).await?; +let provider = Provider::::try_from("https://eth.llamarpc.com")?; let block = provider.get_block(100u64).await?; println!("Got block: {}", serde_json::to_string(&block)?); @@ -68,9 +60,8 @@ Using ENS: ```rust,no_run # use ethers_providers::{Provider, Http, Middleware}; # async fn foo() -> Result<(), Box> { -# let provider = Provider::::try_from( -# "https://mainnet.infura.io/v3/YOUR_API_KEY" -# )?; +let provider = Provider::::try_from("https://eth.llamarpc.com")?; + // Resolve ENS name to Address let name = "vitalik.eth"; let address = provider.resolve_name(name).await?; diff --git a/ethers-providers/src/middleware.rs b/ethers-providers/src/middleware.rs index a5cc533a..8fce071f 100644 --- a/ethers-providers/src/middleware.rs +++ b/ethers-providers/src/middleware.rs @@ -242,7 +242,7 @@ pub trait Middleware: Sync + Send + Debug { /// # use std::convert::TryFrom; /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { - /// # let provider = Provider::::try_from("https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27").unwrap(); + /// # let provider = Provider::::try_from("https://eth.llamarpc.com").unwrap(); /// let avatar = provider.resolve_avatar("parishilton.eth").await.unwrap(); /// assert_eq!(avatar.to_string(), "https://i.imgur.com/YW3Hzph.jpg"); /// # } @@ -264,7 +264,7 @@ pub trait Middleware: Sync + Send + Debug { /// # use std::{str::FromStr, convert::TryFrom}; /// # #[tokio::main(flavor = "current_thread")] /// # async fn main() { - /// # let provider = Provider::::try_from("https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27").unwrap(); + /// # let provider = Provider::::try_from("https://eth.llamarpc.com").unwrap(); /// let token = ethers_providers::erc::ERCNFT::from_str("erc721:0xc92ceddfb8dd984a89fb494c376f9a48b999aafc/9018").unwrap(); /// let token_image = provider.resolve_nft(token).await.unwrap(); /// assert_eq!(token_image.to_string(), "https://creature.mypinata.cloud/ipfs/QmNwj3aUzXfG4twV3no7hJRYxLLAWNPk6RrfQaqJ6nVJFa/9018.jpg"); diff --git a/ethers-providers/src/rpc/provider.rs b/ethers-providers/src/rpc/provider.rs index df657258..5f835393 100644 --- a/ethers-providers/src/rpc/provider.rs +++ b/ethers-providers/src/rpc/provider.rs @@ -87,7 +87,7 @@ impl FromStr for NodeClient { /// use std::convert::TryFrom; /// /// let provider = Provider::::try_from( -/// "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27" +/// "https://eth.llamarpc.com" /// ).expect("could not instantiate HTTP Provider"); /// /// let block = provider.get_block(100u64).await?; @@ -1387,20 +1387,20 @@ mod sealed { /// /// Note that this will send an RPC to retrieve the chain id. /// -/// ``` +/// ```no_run /// # use ethers_providers::{Http, Provider, ProviderExt}; /// # async fn t() { -/// let http_provider = Provider::::connect("https://eth-mainnet.alchemyapi.io/v2/API_KEY").await; +/// let http_provider = Provider::::connect("https://eth.llamarpc.com").await; /// # } /// ``` /// /// This is essentially short for /// -/// ``` +/// ```no_run /// use std::convert::TryFrom; /// use ethers_core::types::Chain; /// use ethers_providers::{Http, Provider, ProviderExt}; -/// let http_provider = Provider::::try_from("https://eth-mainnet.alchemyapi.io/v2/API_KEY").unwrap().set_chain(Chain::Mainnet); +/// let http_provider = Provider::::try_from("https://eth.llamarpc.com").unwrap().set_chain(Chain::Mainnet); /// ``` #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] diff --git a/examples/anvil/examples/anvil_fork.rs b/examples/anvil/examples/anvil_fork.rs index 4fecb8e8..0b615e13 100644 --- a/examples/anvil/examples/anvil_fork.rs +++ b/examples/anvil/examples/anvil_fork.rs @@ -6,8 +6,7 @@ use eyre::Result; #[tokio::main] async fn main() -> Result<()> { // ensure `anvil` is available in $PATH - let anvil = - Anvil::new().fork("https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27").spawn(); + let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); println!("Anvil running at `{}`", anvil.endpoint()); diff --git a/examples/contracts/examples/abigen.rs b/examples/contracts/examples/abigen.rs index f475dc17..f2db769a 100644 --- a/examples/contracts/examples/abigen.rs +++ b/examples/contracts/examples/abigen.rs @@ -63,7 +63,7 @@ async fn rust_inline_generation() -> Result<()> { ]"#, ); - const RPC_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + const RPC_URL: &str = "https://eth.llamarpc.com"; const WETH_ADDRESS: &str = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; let provider = Provider::::try_from(RPC_URL)?; diff --git a/examples/contracts/examples/events.rs b/examples/contracts/examples/events.rs index 4039d883..a0deb71e 100644 --- a/examples/contracts/examples/events.rs +++ b/examples/contracts/examples/events.rs @@ -14,7 +14,7 @@ abigen!( ]"#, ); -const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const WSS_URL: &str = "wss://eth.llamarpc.com"; const WETH_ADDRESS: &str = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; #[tokio::main] diff --git a/examples/contracts/examples/events_with_meta.rs b/examples/contracts/examples/events_with_meta.rs index ceb0c68e..6d6df1f6 100644 --- a/examples/contracts/examples/events_with_meta.rs +++ b/examples/contracts/examples/events_with_meta.rs @@ -17,9 +17,7 @@ abigen!( #[tokio::main] async fn main() -> Result<()> { - let client = - Provider::::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27") - .await?; + let client = Provider::::connect("wss://eth.llamarpc.com").await?; let client = Arc::new(client); diff --git a/examples/events/examples/filtering.rs b/examples/events/examples/filtering.rs index d1ab9092..a968cf10 100644 --- a/examples/events/examples/filtering.rs +++ b/examples/events/examples/filtering.rs @@ -5,7 +5,7 @@ use ethers::{ use eyre::Result; use std::sync::Arc; -const HTTP_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const HTTP_URL: &str = "https://eth.llamarpc.com"; const V3FACTORY_ADDRESS: &str = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; const DAI_ADDRESS: &str = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; const USDC_ADDRESS: &str = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; diff --git a/examples/middleware/examples/builder.rs b/examples/middleware/examples/builder.rs index c9fb058a..c2a3090c 100644 --- a/examples/middleware/examples/builder.rs +++ b/examples/middleware/examples/builder.rs @@ -10,7 +10,7 @@ use ethers::{ }; use std::convert::TryFrom; -const RPC_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const RPC_URL: &str = "https://eth.llamarpc.com"; const SIGNING_KEY: &str = "fdb33e2105f08abe41a8ee3b758726a31abdd57b7a443f470f23efce853af169"; /// In ethers-rs, middleware is a way to customize the behavior of certain aspects of the library by diff --git a/examples/middleware/examples/gas_oracle.rs b/examples/middleware/examples/gas_oracle.rs index ea6795aa..fdf41801 100644 --- a/examples/middleware/examples/gas_oracle.rs +++ b/examples/middleware/examples/gas_oracle.rs @@ -73,7 +73,7 @@ async fn polygon() { } async fn provider_oracle() { - const RPC_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + const RPC_URL: &str = "https://eth.llamarpc.com"; let provider = Provider::::try_from(RPC_URL).unwrap(); let oracle = ProviderOracle::new(provider); match oracle.fetch().await { diff --git a/examples/providers/examples/http.rs b/examples/providers/examples/http.rs index f6bce87e..069f7e65 100644 --- a/examples/providers/examples/http.rs +++ b/examples/providers/examples/http.rs @@ -5,7 +5,7 @@ use ethers::prelude::*; use reqwest::header::{HeaderMap, HeaderValue}; use std::sync::Arc; -const RPC_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const RPC_URL: &str = "https://eth.llamarpc.com"; #[tokio::main] async fn main() -> eyre::Result<()> { diff --git a/examples/providers/examples/retry.rs b/examples/providers/examples/retry.rs index 4df2a605..30991b75 100644 --- a/examples/providers/examples/retry.rs +++ b/examples/providers/examples/retry.rs @@ -10,7 +10,7 @@ use ethers::prelude::*; use reqwest::Url; use std::time::Duration; -const RPC_URL: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const RPC_URL: &str = "https://eth.llamarpc.com"; #[tokio::main] async fn main() -> eyre::Result<()> { diff --git a/examples/providers/examples/ws.rs b/examples/providers/examples/ws.rs index d1c339dc..87d42f67 100644 --- a/examples/providers/examples/ws.rs +++ b/examples/providers/examples/ws.rs @@ -6,7 +6,7 @@ use ethers::prelude::*; -const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const WSS_URL: &str = "wss://eth.llamarpc.com"; #[tokio::main] async fn main() -> eyre::Result<()> { diff --git a/examples/queries/examples/paginated_logs.rs b/examples/queries/examples/paginated_logs.rs index 563b90f1..f3cd63b8 100644 --- a/examples/queries/examples/paginated_logs.rs +++ b/examples/queries/examples/paginated_logs.rs @@ -10,9 +10,7 @@ use std::sync::Arc; #[tokio::main] async fn main() -> Result<()> { - let client: Provider = - Provider::::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27") - .await?; + let client: Provider = Provider::::connect("wss://eth.llamarpc.com").await?; let client = Arc::new(client); let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap(); diff --git a/examples/queries/examples/uniswapv2_pair.rs b/examples/queries/examples/uniswapv2_pair.rs index c9d306da..8cadae92 100644 --- a/examples/queries/examples/uniswapv2_pair.rs +++ b/examples/queries/examples/uniswapv2_pair.rs @@ -17,9 +17,7 @@ abigen!( #[tokio::main] async fn main() -> Result<()> { - let client = Provider::::try_from( - "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27", - )?; + let client = Provider::::try_from("https://eth.llamarpc.com")?; let client = Arc::new(client); // ETH/USDT pair on Uniswap V2 diff --git a/examples/subscriptions/examples/subscribe_events_by_type.rs b/examples/subscriptions/examples/subscribe_events_by_type.rs index 8f935c0b..4de7e05e 100644 --- a/examples/subscriptions/examples/subscribe_events_by_type.rs +++ b/examples/subscriptions/examples/subscribe_events_by_type.rs @@ -46,7 +46,5 @@ async fn main() -> Result<(), Box> { } async fn get_client() -> Provider { - Provider::::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27") - .await - .unwrap() + Provider::::connect("wss://eth.llamarpc.com").await.unwrap() } diff --git a/examples/subscriptions/examples/subscribe_logs.rs b/examples/subscriptions/examples/subscribe_logs.rs index 3ee71259..501bb4a4 100644 --- a/examples/subscriptions/examples/subscribe_logs.rs +++ b/examples/subscriptions/examples/subscribe_logs.rs @@ -10,9 +10,7 @@ use std::sync::Arc; #[tokio::main] async fn main() -> Result<()> { - let client = - Provider::::connect("wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27") - .await?; + let client = Provider::::connect("wss://eth.llamarpc.com").await?; let client = Arc::new(client); let last_block = client.get_block(BlockNumber::Latest).await?.unwrap().number.unwrap(); diff --git a/examples/subscriptions/examples/watch_blocks.rs b/examples/subscriptions/examples/watch_blocks.rs index 38fb90e5..2e38661a 100644 --- a/examples/subscriptions/examples/watch_blocks.rs +++ b/examples/subscriptions/examples/watch_blocks.rs @@ -4,7 +4,7 @@ use std::time::Duration; #[tokio::main] async fn main() -> Result<()> { - let ws_endpoint = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229eddaca27"; + let ws_endpoint = "wss://eth.llamarpc.com"; let ws = Ws::connect(ws_endpoint).await?; let provider = Provider::new(ws).interval(Duration::from_millis(2000)); let mut stream = provider.watch_blocks().await?.take(1); diff --git a/examples/transactions/examples/ens.rs b/examples/transactions/examples/ens.rs index 0606288e..8abbcbe5 100644 --- a/examples/transactions/examples/ens.rs +++ b/examples/transactions/examples/ens.rs @@ -7,8 +7,7 @@ use eyre::Result; #[tokio::main] async fn main() -> Result<()> { // fork mainnet - let anvil = - Anvil::new().fork("https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27").spawn(); + let anvil = Anvil::new().fork("https://eth.llamarpc.com").spawn(); let from = anvil.addresses()[0]; // connect to the network let provider = Provider::::try_from(anvil.endpoint()).unwrap().with_sender(from); diff --git a/examples/transactions/examples/gas_price_usd.rs b/examples/transactions/examples/gas_price_usd.rs index eef46a72..b9773898 100644 --- a/examples/transactions/examples/gas_price_usd.rs +++ b/examples/transactions/examples/gas_price_usd.rs @@ -23,7 +23,7 @@ abigen!( const ETH_DECIMALS: u32 = 18; const USD_PRICE_DECIMALS: u32 = 8; const ETH_USD_FEED: &str = "0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419"; -const RPC_URI: &str = "https://mainnet.infura.io/v3/c60b0bb42f8a4c6481ecd229eddaca27"; +const RPC_URI: &str = "https://eth.llamarpc.com"; /// Retrieves the USD amount per gas unit, using a Chainlink price oracle. /// Function gets the amount of `wei` to be spent per gas unit then multiplies