Skip to content

Commit 564cd9c

Browse files
manuelwedlerAniket-Engg
authored andcommitted
Fix verification on Etherscan with no constructor arguments
Ensure default ConstructorArguments values are set correctly when no constructorArgs are present.
1 parent 3b75a12 commit 564cd9c

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

apps/contract-verification/src/app/components/ConstructorArguments.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export const ConstructorArguments: React.FC<ConstructorArgumentsProps> = ({ abiE
2222
const compiledContract = selectedCompilerAbstract?.data?.contracts?.[filePath]?.[contractName]
2323
const abi = compiledContract?.abi
2424

25-
const constructorArgs = abi && abi.find((a) => a.type === 'constructor')?.inputs
25+
const abiConstructorArgs = abi && abi.find((a) => a.type === 'constructor')?.inputs
26+
const constructorArgs = abiConstructorArgs || []
2627

2728
const decodeConstructorArgs = (value: string) => {
2829
try {
@@ -51,16 +52,16 @@ export const ConstructorArguments: React.FC<ConstructorArgumentsProps> = ({ abiE
5152
useEffect(() => {
5253
// Ensures that error is not reset when tabs are switched
5354
if ((!abiEncodingError && !abiEncodedConstructorArgs) || !constructorArgsInInitialState.current) {
54-
setAbiEncodingError(constructorArgs?.length === 0 ? '' : 'Some constructor arguments are missing')
55+
setAbiEncodingError(constructorArgs.length === 0 ? '' : 'Some constructor arguments are missing')
5556
}
5657

5758
if (constructorArgsInInitialState.current) {
5859
constructorArgsInInitialState.current = false
5960
return
6061
}
6162
setAbiEncodedConstructorArgs('')
62-
setConstructorArgsValues(Array(constructorArgs?.length ?? 0).fill(''))
63-
}, [constructorArgs])
63+
setConstructorArgsValues(Array(constructorArgs.length).fill(''))
64+
}, [abiConstructorArgs])
6465

6566
const handleConstructorArgs = (value: string, index: number) => {
6667
const changedConstructorArgsValues = [...constructorArgsValues.slice(0, index), value, ...constructorArgsValues.slice(index + 1)]
@@ -104,7 +105,7 @@ export const ConstructorArguments: React.FC<ConstructorArgumentsProps> = ({ abiE
104105
if (!selectedContract) return null
105106
if (!compilationOutput && Object.keys(compilationOutput).length === 0) return null
106107
// No render if no constructor args
107-
if (!constructorArgs || constructorArgs.length === 0) return null
108+
if (constructorArgs.length === 0) return null
108109

109110
return (
110111
<div className="mt-4">

0 commit comments

Comments
 (0)