Skip to content

Commit

Permalink
Merge pull request #1135 from shuklaayush/master
Browse files Browse the repository at this point in the history
Add support for `POLYGONSCAN_TOKEN` env var
  • Loading branch information
iamdefinitelyahuman authored Jul 15, 2021
2 parents 4a399b1 + 2961622 commit 546a5d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://github.com/eth-brownie/brownie)
- Add polygon network integration ([#1119](https://github.com/eth-brownie/brownie/pull/1119))
- Fixed subcalls to empty accounts not appearing in the subcalls property of TransactionReceipts ([#1106](https://github.com/eth-brownie/brownie/pull/1106))
- Add support for `POLYGONSCAN_TOKEN` env var ([#1135](https://github.com/eth-brownie/brownie/pull/1135))

### Added
- Added `LocalAccount.sign_message` method to sign `EIP712Message` objects ([#1097](https://github.com/eth-brownie/brownie/pull/1097))
Expand Down
4 changes: 2 additions & 2 deletions brownie/data/network-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ live:
explorer: https://api.ftmscan.com/api
- name: Polygon
networks:
- name: Mainnet
- name: Mainnet (Infura)
chainid: 137
id: polygon-main (Infura)
id: polygon-main
host: https://polygon-mainnet.infura.io/v3/$WEB3_INFURA_PROJECT_ID
explorer: https://api.polygonscan.com/api
- name: Mumbai Testnet (Infura)
Expand Down
16 changes: 15 additions & 1 deletion brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,11 @@ def publish_source(self, contract: Any, silent: bool = False) -> bool:
"""Flatten contract and publish source on the selected explorer"""

# Check required conditions for verifying
explorer_tokens = {"etherscan": "ETHERSCAN_TOKEN", "bscscan": "BSCSCAN_TOKEN"}
explorer_tokens = {
"etherscan": "ETHERSCAN_TOKEN",
"bscscan": "BSCSCAN_TOKEN",
"polygonscan": "POLYGONSCAN_TOKEN",
}
url = CONFIG.active_network.get("explorer")
if url is None:
raise ValueError("Explorer API not set for this network")
Expand Down Expand Up @@ -1878,6 +1882,16 @@ def _fetch_from_explorer(address: str, action: str, silent: bool) -> Dict:
"as the environment variable $BSCSCAN_TOKEN",
BrownieEnvironmentWarning,
)
elif "polygonscan" in url:
if os.getenv("POLYGONSCAN_TOKEN"):
params["apiKey"] = os.getenv("POLYGONSCAN_TOKEN")
elif not silent:
warnings.warn(
"No PolygonScan API token set. You may experience issues with rate limiting. "
"Visit https://polygonscan.com/register to obtain a token, and then store it "
"as the environment variable $POLYGONSCAN_TOKEN",
BrownieEnvironmentWarning,
)

if not silent:
print(
Expand Down

0 comments on commit 546a5d0

Please sign in to comment.