Package: ape-etherscan
Quick StartThe following blockchain explorers are supported in this plugin:Etherscanfor Ethereum networks.Ftmscanfor Fantom networks.Arbiscanfor Arbitrum networks.Optimistic Etherscanfor Optimism networks.Polygonscanfor Polygon networks.Polygonscan ZkEVMfor Polygon ZkEVM networks.Snowtracefor Avalanche networks.Basescanfor Base networks.Bscscanfor Binance-Smart-Chain networks.Dependenciespython3version 3.8 up to 3.11.InstallationviapipYou can install the latest release viapip:pipinstallape-etherscanviasetuptoolsYou can clone the repository and usesetuptoolsfor the most up-to-date version:gitclonehttps://github.com/ApeWorX/ape-etherscan.gitcdape-etherscan
python3setup.pyinstallQuick UsageSet up the environmentSpecify API keys as environment variables. You could put them in your shell's config like~/.profileor use a tool likedirenvand store them locally in.envrc.You can also specify multiple comma-separated keys, a random key will be chosen for each request.
This could be useful if you hit API rate limits.You can obtain an API key by registering with Etherscan and visitingthis page.exportETHERSCAN_API_KEY=SAMPLE_KEYexportFTMSCAN_API_KEY=SAMPLE_KEYexportARBISCAN_API_KEY=SAMPLE_KEYexportPOLYGON_ZKEVM_ETHERSCAN_API_KEY=SAMPLE_KEYexportBASESCAN_API_KEY=SAMPLE_KEYTransaction URLsWhen you have this plugin installed, Etherscan explorer URLs appear in CLI output.INFO:Submitted0x123321123321123321123321123aaaadaaaee4b2aaa07901b80716cc357a9646
etherscanURL:https://rinkeby.etherscan.io/tx/0x123321123321123321123321123aaaadaaaee4b2aaa07901b80716cc357a9646Contract TypesTheape-etherscanplugin also assists in fetchingcontract_types.
Use theContracttop-level construct to create contract instances.
When the explorer plugin locates a contract type for a given address, theContractreturn-value uses that contract type.fromapeimportaccounts,Contractcontract=Contract("0x55a8a39bc9694714e2874c1ce77aa1e599461e18")receipt=contract.call_mutable_method("arg0",sender=accounts.load("acct"))The first linecontract = Contract("0x55a8a39bc9694714e2874c1ce77aa1e599461e18")checks if ape has a cached contract-type for the address0x55a8a39bc9694714e2874c1ce77aa1e599461e18.
If it does not find a cached contract type, it uses an explorer plugin to attempt to find one.
If found, the contract type is then cached to disk and in memory for the active session so that subsequent invocations don't require HTTP calls.
The return value fromContractis aContractInstance, so it is connected to your active provider and ready for transactions.NOTE: Vyper contracts from Etherscan always return the nameVyper_contract.
However, if the plugin detects that the contract type has a method namedsymbol, it will use the return value from that call instead.Contract VerificationUse theape-etherscanplugin to publish and verify your contracts.
Contract verification associates a contract type from Ape with an Ethereum address on Etherscan.
Learn more about Etherscan verificationhere.To verify contract in Ape, you can set thepublishkey toTruewhen deploying:fromapeimportaccounts,projectaccount=accounts.load("testnetacct")account.deploy(project.MyContract,publish=True)You can also use the explorer class directly to publish at a later time:fromapeimportnetworksetherscan=networks.provider.network.exploreretherscan.publish_contract("0x55a8a39bc9694714e2874c1ce77aa1e599461e18")Not every network's explorer supports multi-file verification.
For those networks, the corresponding compiler plugin'sflattenfunctionality is invoked, in order to verify the contract as a single file.NOTE: You must set an Etherscan API key environment variable to use the publishing feature.Custom NetworksIf you would like to use ape-etherscan with yourcustom network configuration, you can use the same network identifier you used to configure it.
For instance, with a custom Ethereum network called "apechain" your configuration might look something like this:networks:custom:-name:apechainchain_id:31337geth:ethereum:apechain:uri:http://localhost:8545etherscan:ethereum:rate_limit:15apechain:uri:https://custom.scanapi_uri:https://api.custom.scan/apiDependenciesYou can use dependencies from Etherscan in your projects.
Configure them like this:dependencies:-name:Sporketherscan:"0xb624FdE1a972B1C89eC1dAD691442d5E8E891469"ecosystem:ethereumnetwork:mainnetThen, access contract types from the dependency in your code:fromapeimportprojectspork_contract_type=project.dependencies["Spork"]["etherscan"].Spork