Skip to content

Commit 1ba2091

Browse files
committed
feat: check check constructor args type
1 parent 5bcaec5 commit 1ba2091

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/hardhat-verify/src/internal/utilities.ts

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919

2020
import { LibraryToAddress } from "./solc/artifacts";
2121
import {
22+
ABIArgumentTypeErrorType,
2223
isABIArgumentLengthError,
2324
isABIArgumentOverflowError,
2425
isABIArgumentTypeError,
@@ -228,6 +229,23 @@ export async function encodeArguments(
228229
const contractInterface = new Interface(abi);
229230
let encodedConstructorArguments;
230231
try {
232+
// Check if the constructor arguments are of the correct type.
233+
const constructorArgType = contractInterface.deploy.inputs?.map(
234+
(ci) => ci?.type
235+
);
236+
constructorArguments?.forEach((item, index) => {
237+
if (
238+
typeof item !== constructorArgType[index] &&
239+
constructorArgType[index] === "string"
240+
)
241+
throw new ABIArgumentTypeError({
242+
code: "INVALID_ARGUMENT",
243+
argument: "constructor argument",
244+
value: item,
245+
reason: `Expected type 'string', but got '${typeof item}'`,
246+
} as ABIArgumentTypeErrorType);
247+
});
248+
231249
encodedConstructorArguments = contractInterface
232250
.encodeDeploy(constructorArguments)
233251
.replace("0x", "");

0 commit comments

Comments
 (0)