diff --git a/packages/thirdweb/src/utils/abi/normalizeFunctionParams.test.ts b/packages/thirdweb/src/utils/abi/normalizeFunctionParams.test.ts index 35d377f10c8..79ed5fc09ff 100644 --- a/packages/thirdweb/src/utils/abi/normalizeFunctionParams.test.ts +++ b/packages/thirdweb/src/utils/abi/normalizeFunctionParams.test.ts @@ -56,7 +56,7 @@ describe("normalizeFunctionParams", () => { }); it("should throw an error if a parameter name is missing", () => { - const abiFunction: AbiFunction = { + let abiFunction: AbiFunction = { inputs: [{ name: undefined, type: "uint256" }], type: "function", stateMutability: "pure", @@ -67,6 +67,31 @@ describe("normalizeFunctionParams", () => { expect(() => normalizeFunctionParams(abiFunction, {})).toThrow( "Missing named parameter for test at index 0", ); + + abiFunction = { + inputs: [{ name: "", type: "uint256" }], + type: "function", + stateMutability: "pure", + name: "test", + outputs: [], + }; + + expect(() => normalizeFunctionParams(abiFunction, {})).toThrow( + "Missing named parameter for test at index 0", + ); + + abiFunction = { + inputs: [{ name: undefined, type: "uint256" }], + type: "function", + stateMutability: "pure", + name: "test", + outputs: [], + }; + + const normalized = normalizeFunctionParams(abiFunction, { "*": 123 }); + + expect(normalized.length).to.eq(1); + expect(normalized[0]).to.eq(123); }); it("should throw an error if a parameter value is missing", () => { diff --git a/packages/thirdweb/src/utils/abi/normalizeFunctionParams.ts b/packages/thirdweb/src/utils/abi/normalizeFunctionParams.ts index 92fb86e1ce3..70b1d6d1335 100644 --- a/packages/thirdweb/src/utils/abi/normalizeFunctionParams.ts +++ b/packages/thirdweb/src/utils/abi/normalizeFunctionParams.ts @@ -13,10 +13,15 @@ export function normalizeFunctionParams( abiFunction.inputs.map((i) => i.type), abiFunction.inputs.map((input, index) => { const value = input.name; - if (value === undefined) { - throw new Error( - `Missing named parameter for ${"name" in abiFunction ? abiFunction.name : "constructor"} at index ${index}`, - ); + if (value === undefined || value.length === 0) { + // TODO: Handle multiple unnamed params + if (!params["*"]) { + throw new Error( + `Missing named parameter for ${"name" in abiFunction ? abiFunction.name : "constructor"} at index ${index}`, + ); + } + + return params["*"]; } const valueWithoutUnderscore = value.replace(/^_+/, ""); const normalizedValue =