Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the contract ABI not passed, the deploy method (the smart contract constructor) does not accept parameters #6634

Closed
Muhammad-Altabba opened this issue Dec 3, 2023 · 0 comments · Fixed by #6635
Assignees
Labels

Comments

@Muhammad-Altabba
Copy link
Contributor

Muhammad-Altabba commented Dec 3, 2023

If the contract ABI not passed the smart contract constructor does not accept parameters

Expected behavior

If the ABI was not passed (technically it is given as []) then the type checking for the constructor should allow passing parameters. And also no error is thorwn.

Actual behavior

If the ABI was passed as [], the developer can call the deploy; But there will be an error if parameter(s) where passed.

If the user tried to work around this by using // @ts-expect-error, an error will come at runtime:

Web3ContractError: The number of arguments is not matching the methods required number. You need to pass 0 arguments.

  125 |     console.log(abi);
  126 |     if (inputLength !== args.length) {
> 127 |             throw new Web3ContractError(
      |                   ^
  128 |                     `The number of arguments is not matching the methods required number. You need to pass ${inputLength} arguments.`,
  129 |             );
  130 |     }

  at encodeMethodABI (src/encoding.ts:127:9)
  at dataInputEncodeMethodHelper (src/utils.ts:45:14)
  at dataInputEncodeMethodHelper (src/utils.ts:94:20)
  at Contract._contractMethodDeploySend (src/contract.ts:1112:14)
  at Object._contractMethodDeploySend [as send] (src/contract.ts:640:17)
  at test/unit/contract.test.ts:288:6
  at test/unit/contract.test.ts:47:71
  at Object.<anonymous>.__awaiter (test/unit/contract.test.ts:43:12)

Steps to reproduce the behavior

const fromAccount = '0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1';
const contract = new web3.eth.Contract([]);

const contractDeployed = await contract
  .deploy({
    arguments: [1000], // Error: Type 'number[]' is not assignable to type 'undefined'.
  })
  .send({
    from: fromAccount,
    gas: '1000000',
  });

Environment

web3 v4

@Muhammad-Altabba Muhammad-Altabba added the 4.x 4.0 related label Dec 3, 2023
@Muhammad-Altabba Muhammad-Altabba changed the title If the contract ABI not passed, the types of the contract constructor and the methods does not accept parameters If the contract ABI not passed, the deploy method (the smart contract constructor) does not accept parameters Dec 3, 2023
@mconnelly8 mconnelly8 added the Bug Addressing a bug label Dec 12, 2023
@mconnelly8 mconnelly8 removed the Bug Addressing a bug label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants