diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index acb8720e..41a1b777 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -1,11 +1,12 @@ -use serde::Deserialize; -use thiserror::Error; - -use core::convert::TryFrom; -use std::{convert::TryInto, default, fmt, str::FromStr}; - use crate::types::U256; +use serde::Deserialize; +use std::{ + convert::{TryFrom, TryInto}, + fmt, + str::FromStr, +}; use strum::EnumVariantNames; +use thiserror::Error; #[derive(Debug, Clone, Error)] #[error("Failed to parse chain: {0}")] @@ -26,6 +27,7 @@ pub enum Chain { Polygon = 137, Fantom = 250, Dev = 1337, + AnvilHardhat = 31337, FantomTestnet = 4002, PolygonMumbai = 80001, Avalanche = 43114, @@ -86,6 +88,7 @@ impl fmt::Display for Chain { Chain::Oasis => "oasis", Chain::Emerald => "emerald", Chain::EmeraldTestnet => "emerald-testnet", + Chain::AnvilHardhat => "anvil-hardhat", }; write!(formatter, "{}", chain) @@ -123,6 +126,7 @@ impl TryFrom for Chain { 100 => Chain::XDai, 137 => Chain::Polygon, 1337 => Chain::Dev, + 31337 => Chain::Dev, 250 => Chain::Fantom, 4002 => Chain::FantomTestnet, 80001 => Chain::PolygonMumbai, @@ -185,6 +189,7 @@ impl FromStr for Chain { "fantom" => Chain::Fantom, "fantom-testnet" => Chain::FantomTestnet, "dev" => Chain::Dev, + "anvil" | "hardhat" | "anvil-hardhat" => Chain::AnvilHardhat, "bsc" => Chain::BinanceSmartChain, "bsc-testnet" => Chain::BinanceSmartChainTestnet, "arbitrum" => Chain::Arbitrum, @@ -225,7 +230,7 @@ impl Chain { } } -impl default::Default for Chain { +impl Default for Chain { fn default() -> Self { Chain::Mainnet } diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 4f1af333..cc800719 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -1,23 +1,20 @@ //! Bindings for [etherscan.io web api](https://docs.etherscan.io/) +use contract::ContractMetadata; +use errors::EtherscanError; +use ethers_core::{ + abi::{Abi, Address}, + types::{Chain, H256}, +}; +use reqwest::{header, IntoUrl, Url}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::{ borrow::Cow, io::Write, path::PathBuf, time::{Duration, SystemTime, UNIX_EPOCH}, }; - -use contract::ContractMetadata; -use reqwest::{header, IntoUrl, Url}; -use serde::{de::DeserializeOwned, Deserialize, Serialize}; use tracing::trace; - -use errors::EtherscanError; -use ethers_core::{ - abi::{Abi, Address}, - types::{Chain, H256}, -}; - pub mod account; pub mod contract; pub mod errors; @@ -108,7 +105,9 @@ impl Client { Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => { std::env::var("MOONSCAN_API_KEY")? } - Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported), + Chain::AnvilHardhat | Chain::Dev => { + return Err(EtherscanError::LocalNetworksNotSupported) + } }; Self::new(chain, api_key) } @@ -297,7 +296,9 @@ impl ClientBuilder { "https://testnet.explorer.emerald.oasis.dev/api", "https://testnet.explorer.emerald.oasis.dev/", ), - Chain::Dev => return Err(EtherscanError::LocalNetworksNotSupported), + Chain::AnvilHardhat | Chain::Dev => { + return Err(EtherscanError::LocalNetworksNotSupported) + } chain => return Err(EtherscanError::ChainNotSupported(chain)), }; self.with_api_url(etherscan_api_url?)?.with_url(etherscan_url?)