Skip to content

Commit

Permalink
feat: supported chains
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Oct 17, 2024
1 parent 4b466ae commit 51b1752
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
25 changes: 25 additions & 0 deletions ape_etherscan/explorer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import json
from typing import Optional

import requests
from ape.api import ExplorerAPI, PluginConfig
from ape.contracts import ContractInstance
from ape.exceptions import ProviderNotConnectedError
from ape.managers.project import ProjectManager
from ape.types import AddressType, ContractType
from ape.utils import ZERO_ADDRESS

from ethpm_types import Compiler, PackageManifest
from ethpm_types.source import Source
from evmchains import PUBLIC_CHAIN_META

from ape_etherscan.client import (
ClientFactory,
Expand All @@ -18,6 +22,7 @@
from ape_etherscan.exceptions import ContractNotVerifiedError
from ape_etherscan.types import EtherscanInstance
from ape_etherscan.verify import SourceVerifier
from ape_etherscan.utils import NETWORKS


class Etherscan(ExplorerAPI):
Expand Down Expand Up @@ -47,6 +52,26 @@ def etherscan_api_uri(self):
self._config, self.network.ecosystem.name, self.network.name.replace("-fork", "")
)

@classmethod
def get_supported_chains(cls) -> list[dict]:
"""
Get a list of chain data for all chains Etherscan supports.
https://docs.etherscan.io/contract-verification/supported-chains
Returns:
list[dict]
"""
response = requests.get("https://api.etherscan.io/v2/chainlist")
response.raise_for_status()
data = response.json()
return data.get("result", [])

@classmethod
def supports_chain(cls, chain_id: int) -> bool:
chain_data = cls.get_supported_chains()
chain_ids = [int(c["chainid"]) for c in chain_data if "chainid" in c]
return chain_id in chain_ids

def get_address_url(self, address: str) -> str:
return f"{self.etherscan_uri}/address/{address}"

Expand Down
6 changes: 3 additions & 3 deletions ape_etherscan/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# TODO: Remove in 0.9 and make this a calculated property.
# TODO: (deprecated) Remove in 0.9 and make this a calculated property.
API_KEY_ENV_KEY_MAP = {
"arbitrum": "ARBISCAN_API_KEY",
"avalanche": "SNOWTRACE_API_KEY",
Expand All @@ -20,11 +20,11 @@
"unichain": "UNISCAN_API_KEY",
}
NETWORKS = {
"arbitrum": [
"arbitrum": {
"mainnet",
"sepolia",
"nova",
],
},
"avalanche": [
"mainnet",
"fuji",
Expand Down

0 comments on commit 51b1752

Please sign in to comment.