Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
[draft] Add Optimism & OptimismKovan chains (#737)
Browse files Browse the repository at this point in the history
* core: Add Optimism & OptimismKovan chains

* etherscan: Add ETHERSCAN_API_KEY to optimism network
  • Loading branch information
pyk authored Dec 25, 2021
1 parent 47e1887 commit 3f095f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum Chain {
Moonbeam,
MoonbeamDev,
Moonriver,
Optimism,
OptimismKovan,
}

impl fmt::Display for Chain {
Expand All @@ -43,6 +45,8 @@ impl From<Chain> for u32 {
Chain::Moonbeam => 1287,
Chain::MoonbeamDev => 1281,
Chain::Moonriver => 1285,
Chain::Optimism => 10,
Chain::OptimismKovan => 69,
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions ethers-etherscan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ impl Client {
Url::parse("https://api-testnet.snowtrace.io/api"),
Url::parse("https://testnet.snowtrace.io"),
),
Chain::Optimism => (
Url::parse("https://api-optimistic.etherscan.io/api"),
Url::parse("https://optimistic.etherscan.io"),
),
Chain::OptimismKovan => (
Url::parse("https://api-kovan-optimistic.etherscan.io/api"),
Url::parse("https://kovan-optimistic.etherscan.io"),
),
chain => return Err(EtherscanError::ChainNotSupported(chain)),
};

Expand All @@ -75,9 +83,13 @@ impl Client {
let api_key = match chain {
Chain::Avalanche | Chain::AvalancheFuji => std::env::var("SNOWTRACE_API_KEY")?,
Chain::Polygon | Chain::PolygonMumbai => std::env::var("POLYGONSCAN_API_KEY")?,
Chain::Mainnet | Chain::Ropsten | Chain::Kovan | Chain::Rinkeby | Chain::Goerli => {
std::env::var("ETHERSCAN_API_KEY")?
}
Chain::Mainnet
| Chain::Ropsten
| Chain::Kovan
| Chain::Rinkeby
| Chain::Goerli
| Chain::Optimism
| Chain::OptimismKovan => std::env::var("ETHERSCAN_API_KEY")?,

Chain::XDai | Chain::Sepolia => String::default(),
Chain::Moonbeam | Chain::MoonbeamDev | Chain::Moonriver => {
Expand Down

0 comments on commit 3f095f4

Please sign in to comment.