Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Add forceConstructorArgs feature (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellwolf authored May 7, 2021
1 parent 52f1b67 commit 7f27e02
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ You can optionally provide an explicit address of the contract(s) that you wish
truffle run verify SimpleStorage@0x61C9157A9EfCaf6022243fA65Ef4666ECc9FD3D7 --network rinkeby
```
### Constructor arguments override (Optional)
You can additionally provide an explicit constructor arguments for the contract using the `--forceConstructorArgs` option. This is useful if the contract was created by another contract rather an EOA, because truffle-plugin-verify cannot automatically retrieve constructor arguments in these cases. Note that the value needs to be prefixed with `string:` (e.g. `--forceConstructorArgs string:0000`).
```
truffle run verify MetaCoin --forceConstructorArgs string:0000000000000000000000000cb966d6a7702a4eff64009502653e302b3ec365 --network goerli
```
### Debugging
You can pass an optional `--debug` flag into the plugin to display debug messages during the verification process. This is generally not necessary, but can be used to provide additional information when the plugin appears to malfunction.
Expand Down
16 changes: 12 additions & 4 deletions verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const { version } = require('./package.json')
const logger = cliLogger({ level: 'info' })

module.exports = async (config) => {
const options = parseConfig(config)

// Set debug logging
if (config.debug) logger.level('debug')
logger.debug('DEBUG logging is turned ON')
logger.debug(`Running truffle-plugin-verify v${version}`)

const options = parseConfig(config)

// Verify each contract
const contractNameAddressPairs = config._.slice(1)

Expand Down Expand Up @@ -90,12 +90,20 @@ const parseConfig = (config) => {
const workingDir = config.working_directory
const contractsBuildDir = config.contracts_build_directory

let forceConstructorArgsType, forceConstructorArgs
if (config.forceConstructorArgs) {
[forceConstructorArgsType, forceConstructorArgs] = config.forceConstructorArgs.split(':')
enforce(forceConstructorArgsType === 'string', 'Force constructor args must be string type', logger)
logger.debug(`Force custructor args provided: 0x${forceConstructorArgs}`)
}

return {
apiUrl,
apiKey,
networkId,
workingDir,
contractsBuildDir
contractsBuildDir,
forceConstructorArgs
}
}

Expand Down Expand Up @@ -128,7 +136,7 @@ const verifyContract = async (artifact, options) => {

const sendVerifyRequest = async (artifact, options) => {
const compilerVersion = extractCompilerVersion(artifact)
const encodedConstructorArgs = await fetchConstructorValues(artifact, options)
const encodedConstructorArgs = options.forceConstructorArgs || await fetchConstructorValues(artifact, options)
const inputJSON = getInputJSON(artifact, options)

const postQueries = {
Expand Down

0 comments on commit 7f27e02

Please sign in to comment.