@@ -229,21 +229,22 @@ export async function encodeArguments(
229
229
const contractInterface = new Interface ( abi ) ;
230
230
let encodedConstructorArguments ;
231
231
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 ) => {
232
+ // encodeDeploy doesn't catch subtle type mismatches, such as a number
233
+ // being passed when a string is expected, so we have to validate the
234
+ // scenario manually.
235
+ const expectedConstructorArgs = contractInterface . deploy . inputs ;
236
+ constructorArguments . forEach ( ( arg , i ) => {
237
237
if (
238
- typeof item !== constructorArgType [ index ] &&
239
- constructorArgType [ index ] = == "string"
240
- )
238
+ expectedConstructorArgs [ i ] ?. type === "string" &&
239
+ typeof arg ! == "string"
240
+ ) {
241
241
throw new ABIArgumentTypeError ( {
242
242
code : "INVALID_ARGUMENT" ,
243
- argument : "constructor argument" ,
244
- value : item ,
245
- reason : `Expected type ' string', but got ' ${ typeof item } '` ,
243
+ argument : expectedConstructorArgs [ i ] . name ,
244
+ value : arg ,
245
+ reason : "invalid string value" ,
246
246
} as ABIArgumentTypeErrorType ) ;
247
+ }
247
248
} ) ;
248
249
249
250
encodedConstructorArguments = contractInterface
0 commit comments