From 75fbec07069528d32e4c9954a3f894f27ead8b61 Mon Sep 17 00:00:00 2001 From: 0xTomoyo <0xtomoyo@protonmail.com> Date: Sun, 6 Feb 2022 01:36:21 +1100 Subject: [PATCH] feat(chain): add arbitrum support (#869) * feat: add arbitrum chainid & block explorer * chore: update changelog * feat: add arbitrum to is_legacy Co-authored-by: Georgios Konstantopoulos --- CHANGELOG.md | 1 + ethers-core/src/types/chain.rs | 10 +++++++++- ethers-etherscan/src/lib.rs | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 190a2885..e3327b8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ [#854](https://github.com/gakonst/ethers-rs/pull/852) - Refactor `ethers-contract-abigen` to use `eyre` instead of `anyhow` via [#858](https://github.com/gakonst/ethers-rs/pull/858) +- Add Arbitrum mainnet and testnet to the list of known chains ## ethers-contract-abigen diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index c31c45ba..c1626fe8 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -34,6 +34,8 @@ pub enum Chain { OptimismKovan = 69, BinanceSmartChain = 56, BinanceSmartChainTestnet = 97, + Arbitrum = 42161, + ArbitrumTestnet = 421611, } impl fmt::Display for Chain { @@ -83,6 +85,8 @@ impl TryFrom for Chain { 69 => Chain::OptimismKovan, 56 => Chain::BinanceSmartChain, 97 => Chain::BinanceSmartChainTestnet, + 42161 => Chain::Arbitrum, + 421611 => Chain::ArbitrumTestnet, _ => return Err(ParseChainError(chain.to_string())), }) } @@ -112,6 +116,8 @@ impl FromStr for Chain { "fantom-testnet" => Chain::FantomTestnet, "bsc" => Chain::BinanceSmartChain, "bsc-testnet" => Chain::BinanceSmartChainTestnet, + "arbitrum" => Chain::Arbitrum, + "arbitrum-testnet" => Chain::ArbitrumTestnet, _ => return Err(ParseChainError(chain.to_owned())), }) } @@ -129,7 +135,9 @@ impl Chain { Chain::Fantom | Chain::FantomTestnet | Chain::BinanceSmartChain | - Chain::BinanceSmartChainTestnet + Chain::BinanceSmartChainTestnet | + Chain::Arbitrum | + Chain::ArbitrumTestnet, ) } } diff --git a/ethers-etherscan/src/lib.rs b/ethers-etherscan/src/lib.rs index 2eaa1702..a1a261d5 100644 --- a/ethers-etherscan/src/lib.rs +++ b/ethers-etherscan/src/lib.rs @@ -80,6 +80,13 @@ impl Client { Url::parse("https://api-testnet.bscscan.com/api"), Url::parse("https://testnet.bscscan.com"), ), + Chain::Arbitrum => { + (Url::parse("https://api.arbiscan.io/api"), Url::parse("https://arbiscan.io")) + } + Chain::ArbitrumTestnet => ( + Url::parse("https://api-testnet.arbiscan.io/api"), + Url::parse("https://testnet.arbiscan.io"), + ), chain => return Err(EtherscanError::ChainNotSupported(chain)), }; @@ -107,7 +114,9 @@ impl Client { Chain::Fantom | Chain::FantomTestnet | Chain::BinanceSmartChain | - Chain::BinanceSmartChainTestnet => std::env::var("ETHERSCAN_API_KEY")?, + Chain::BinanceSmartChainTestnet | + Chain::Arbitrum | + Chain::ArbitrumTestnet => std::env::var("ETHERSCAN_API_KEY")?, Chain::XDai | Chain::Sepolia => String::default(), Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {