Skip to content

feat(forge verify-contract): --guess-constructor-args #6334

@klkvr

Description

@klkvr

Component

Forge

Describe the feature you would like

It would be convenient to have an option to specify --guess-constructor-args flag on forge verify-contract command which will try to find constructor arguments for contract without need to explicitly provide them when running the command.

It can be done in 3 steps:

  1. Fetch contract deployment transaction with Etherscan API: https://docs.etherscan.io/api-endpoints/contracts#get-contract-creator-and-creation-tx-hash
  2. Fetch contract creation code from transaction
  3. Use contract ABI to calculate length of abi-encoded constructor arguments and take a suffix of creation code with this length.

The most interesting part is fetching the creation code (step 2). For contracts deployed by EOAs it is pretty simple (we can just take tx.data field). But for contracts deployed with CREATE/CREATE2 it would require tracing of transaction execution which takes time and requires endpoint with archive data which is not available to everyone.

It might also make sense to add a CLI command forge get-constructor-args <CONTRACT> <CREATION_CODE> which will basically perform a step 3 above. This might be useful because users may have init code from broadcast artifacts or Etherscan UI

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Completed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions