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

Contract methods have parameters with the type any[] #7302

Closed
nicklatkovich opened this issue Oct 4, 2024 · 2 comments · Fixed by #7340
Closed

Contract methods have parameters with the type any[] #7302

nicklatkovich opened this issue Oct 4, 2024 · 2 comments · Fixed by #7340
Assignees
Labels
4.x 4.0 related Bug Addressing a bug P1 High severity bugs

Comments

@nicklatkovich
Copy link

Expected behavior

Contract methods have typed parameters.

Actual behavior

Contract methods have parameters with the type any[].

Steps to reproduce the behavior

import Web3 from "web3";

const abi = [{
  inputs: [
    { internalType: "uint256", name: "testArg1", type: "uint256" },
    { internalType: "uint256", name: "testArg2", type: "uint256" },
  ],
  name: "test",
  outputs: [{ internalType: "uint256", name: "testRes1", type: "uint256" }],
  stateMutability: "nonpayable",
  type: "function",
}] as const;

const web3 = new Web3();
const contract = new web3.eth.Contract(abi);

// Actual: No error occurs here.
// Expected: Error - Expected 2 arguments, but got 0
contract.methods.test();

// Actual: any[]
// Expected: [MatchPrimitiveType<"uint256", unknown>, MatchPrimitiveType<"uint256", unknown>]
type Params = Parameters<typeof contract['methods']['test']>;

Solution

...args: Method['Inputs'] extends undefined | unknown ? any[] : Method['Inputs']

Should be changed to extends never or something similar. Since everything is extending type unknown.

Environment

web3: 4.13.0
typescript: 5.6.2
@mconnelly8
Copy link

Hey @nicklatkovich , I'll have someone look into this soon.

@dstoyanoff
Copy link

Same happens for us. The methods are properly inferred, but the parameters are any[], which is very dangerous

@mconnelly8 mconnelly8 added 4.x 4.0 related Bug Addressing a bug P1 High severity bugs labels Oct 15, 2024
@avkos avkos self-assigned this Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x 4.0 related Bug Addressing a bug P1 High severity bugs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants