Skip to content

feat(cli): add --verify-contract flag to rex deploy#220

Open
ilitteri wants to merge 2 commits intomainfrom
feat/verify-contract
Open

feat(cli): add --verify-contract flag to rex deploy#220
ilitteri wants to merge 2 commits intomainfrom
feat/verify-contract

Conversation

@ilitteri
Copy link
Copy Markdown
Collaborator

@ilitteri ilitteri commented Feb 6, 2026

Motivation

After deploying a contract with rex deploy --contract-path, there's no way to verify the source code on Etherscan. Users have to manually submit verification through the Etherscan web UI or a separate tool. This adds a one-command deploy+verify workflow.

Description

Adds --verify-contract flag to rex deploy that automatically verifies the contract source code on Etherscan after deployment using the Etherscan V2 API.

New CLI flags:

Flag Description
--verify-contract Enable post-deploy Etherscan verification
--etherscan-api-key API key (also reads ETHERSCAN_API_KEY env var)
--contract-name Override contract name for multi-contract files
--optimizations Number of optimizer runs for solc and Etherscan

How it works:

  1. Deploys the contract and waits for the receipt
  2. Builds a Standard JSON Input matching the exact solc flags used during compilation (--via-ir, --no-cbor-metadata, optimizer settings)
  3. Recursively resolves imports to populate the sources map
  4. Submits verification to Etherscan V2 API (retries if Etherscan hasn't indexed the contract yet)
  5. Polls verification status until success

Changes:

  • cli/src/verify.rs — new module with all verification logic
  • cli/src/common.rs — new flags on DeployArgs
  • cli/src/cli.rs — refactored compile_contract_from_path to return CompilationInfo (bytecode + remappings + optimizer settings), deferred artifact cleanup, wired verification after deploy
  • cli/Cargo.toml — added reqwest and regex dependencies
  • cli/README.md — documented the new flags with examples

Tested on Sepolia:

$ rex deploy --contract-path Counter.sol --remappings "" --optimizations 999999 \
    --verify-contract --etherscan-api-key $KEY --private-key $PK \
    --rpc-url https://ethereum-sepolia-rpc.publicnode.com

Compiler run successful. Artifact(s) can be found in directory "./solc_out".
Contract deployed in tx: 0x7f35...
Contract address: 0x2246...

Verifying contract on Etherscan...
  Compiler version: v0.8.31+commit.fd3a2265
  Contract name: Counter
  Submitting verification request...
  [1/12] Waiting for Etherscan to index the contract...
  [2/12] Waiting for Etherscan to index the contract...
  Verification submitted (GUID: vnr1ag...)
  [1/60] Checking verification status...
  Contract is already verified.
  https://sepolia.etherscan.io/address/0x2246...#code

…ation

After deploying a contract via --contract-path, the new --verify-contract flag
automatically verifies the source code on Etherscan using the V2 API. This
submits the Standard JSON Input (matching the exact solc flags used during
compilation) and polls until verification succeeds.

New flags:
- --verify-contract: enable post-deploy verification
- --etherscan-api-key: API key (also reads ETHERSCAN_API_KEY env var)
- --contract-name: override contract name for multi-contract files
- --optimizations: number of optimizer runs passed to solc and Etherscan

The compilation step is refactored to return a CompilationInfo struct so that
remappings and optimizer settings can be forwarded to the verification module.
Artifact cleanup is deferred until after verification completes.
@ilitteri ilitteri requested a review from a team as a code owner February 6, 2026 04:43
@ilitteri ilitteri changed the title Add --verify-contract flag to rex deploy feat(cli): add --verify-contract flag to rex deploy Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant