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

[draft] Add Optimism & OptimismKovan chains #737

Merged
merged 2 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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