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

Commit

Permalink
Add fallback constructor arguments
Browse files Browse the repository at this point in the history
- For fresh factory-deployed contracts the constructor args can't be retrieved
- In this case, empty args will be used as fallback
- This only works if such a contract does not have constructor args,
  which is a very small number, but >0
  • Loading branch information
rkalis committed Mar 23, 2020
1 parent 23e6702 commit 0409378
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ const fetchConstructorValues = async (artifact, options) => {
} catch (e) {
throw new Error(`Failed to connect to Etherscan API at url ${options.apiUrl}`)
}
enforceOrThrow(res.data && res.data.status === RequestStatus.OK, 'Failed to fetch constructor arguments')

// The last part of the transaction data is the constructor parameters
const constructorParameters = res.data.result[0].input.substring(artifact.bytecode.length)
// The last part of the transaction data is the constructor arguments
// If it can't be accessed, try using empty constructor arguments
const constructorParameters = res.data && res.data.status === RequestStatus.OK && res.data.result[0] !== undefined
? res.data.result[0].input.substring(artifact.bytecode.length)
: ''
logger.debug(`Constructor parameters received: 0x${constructorParameters}`)
return constructorParameters
}
Expand Down

0 comments on commit 0409378

Please sign in to comment.