diff --git a/packages/web3-eth-contract/src/contract.ts b/packages/web3-eth-contract/src/contract.ts index 6b1a12295dd..46e4000b9c9 100644 --- a/packages/web3-eth-contract/src/contract.ts +++ b/packages/web3-eth-contract/src/contract.ts @@ -113,7 +113,7 @@ type ContractBoundMethod< Abi extends AbiFunctionFragment, Method extends ContractMethod = ContractMethod, > = ( - ...args: Method['Inputs'] + ...args: Abi extends AbiFunctionFragment ? Method['Inputs'] : any ) => Method['Abi']['stateMutability'] extends 'payable' | 'pure' ? PayableMethodObject : NonPayableMethodObject; diff --git a/packages/web3-eth-contract/test/unit/contract.test.ts b/packages/web3-eth-contract/test/unit/contract.test.ts index e86d04cc4cd..1c86b514716 100644 --- a/packages/web3-eth-contract/test/unit/contract.test.ts +++ b/packages/web3-eth-contract/test/unit/contract.test.ts @@ -1595,6 +1595,39 @@ describe('Contract', () => { spyEstimateGas.mockClear(); }); + it('estimateGas should work for contract method even with no ABI', async () => { + const contract = new Contract([], deployedAddr); + + const spyTx = jest.spyOn(eth, 'sendTransaction').mockImplementation(() => { + const newContract = contract.clone(); + newContract.options.address = deployedAddr; + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return Promise.resolve(newContract) as any; + }); + + const spyEstimateGas = jest + .spyOn(eth, 'estimateGas') + .mockImplementationOnce((_objInstance, _tx, _block) => { + expect(_block).toBe('latest'); + expect(_tx.to).toStrictEqual(deployedAddr); + expect(_tx.from).toStrictEqual(sendOptions.from); + expect(_tx.data).toBe( + '0xa41368620000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000', + ); + + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return Promise.resolve(BigInt(36916)) as any; + }); + + // This produces an error at runtime. + // This needs investigation and fixing. + const result = await contract.methods.setGreeting().estimateGas(sendOptions); + expect(result).toStrictEqual(BigInt(36916)); + + spyTx.mockClear(); + spyEstimateGas.mockClear(); + }); + it('encodeABI should work for contract method', async () => { const arg = 'Hello';