vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
255 stars 51 forks source link

feat: add contract verify on blockscout and etherscan #303

Closed developerfred closed 1 month ago

developerfred commented 2 months ago

ref #267

What I did

I implemented a robust contract verification feature for the Boa framework, enabling seamless verification of deployed smart contracts on both Blockscout and Etherscan explorers. This enhancement significantly augments the developer experience by automating the often cumbersome process of contract verification, thus ensuring transparency and facilitating easier auditing of on-chain code.

How I did it

The implementation was meticulously crafted through the following steps:

  1. Developed a ContractVerifier class that encapsulates the logic for interacting with block explorer APIs, supporting both Blockscout and Etherscan.
  2. Integrated the verification process into the existing VyperDeployer class, allowing for verification to be initiated immediately post-deployment.
  3. Extended the high-level load and loads functions in the Boa framework to accept optional verify and explorer parameters, providing a user-friendly interface for contract deployment with verification.
  4. Implemented comprehensive error handling and reporting to ensure robust operation in various scenarios, including API failures and verification rejections.
  5. Utilized environment variables for secure storage of API keys, adhering to best practices in sensitive data management.
  6. Created detailed documentation, including API references and usage examples, to facilitate easy adoption of the new feature.

How to verify it

To verify the efficacy of this new feature:

  1. Ensure the appropriate environment variables (BLOCKSCOUT_API_KEY or ETHERSCAN_API_KEY) are set in your development environment.
  2. Execute the provided test suite, which includes both unit tests and integration tests simulating various verification scenarios.
  3. Manually deploy and verify a contract using the new API:

    import boa
    contract = boa.loads(source_code,  explorer="blockscout")
    
    # Alternative deployment methodology utilizing the VyperDeployer directly.
    # This granular approach offers enhanced control over the deployment process,
    # potentially facilitating more nuanced configuration options.
    deployer = VyperDeployer(compiler_data, filename="contract.vy")
    contract = deployer.deploy( explorer="etherscan")
    
  4. Check the output for confirmation of successful verification, and cross-reference with the specified block explorer to ensure the contract appears as verified.
  5. Attempt verification with invalid credentials or on an unsupported explorer to confirm proper error handling.

Description for the changelog

Added automated contract verification feature for Blockscout and Etherscan explorers:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

developerfred commented 2 months ago

https://docs.blockscout.com/developer-support/verifying-a-smart-contract/blockscout-smart-contract-verification-api

I will update and test locally

developerfred commented 2 months ago

Screenshot 2024-09-06 at 19 34 53

@charles-cooper @DanielSchiavini

charles-cooper commented 2 months ago

Screenshot 2024-09-06 at 19 34 53

@charles-cooper @DanielSchiavini

Screenshot_20240906_180258_Brave

Did you just take a screenshot of it passing the mock tests?

developerfred commented 2 months ago

yeah, I can make a video too with a contract implemented and verified on the sepolia network

developerfred commented 2 months ago

@charles-cooper Do you think we should create a list of pre-networks available for verification, for example optimism, polygon, sepolia or is this implicit for the developer?

charles-cooper commented 1 month ago

superseded by https://github.com/vyperlang/titanoboa/pull/308