-
Notifications
You must be signed in to change notification settings - Fork 5.1k
web3.eth.Contract.methods.myMethod()
does not accept to insert any parameters.
#6275
Comments
Hi there, thank you for submitting this issue. https://docs.web3js.org/guides/smart_contracts/infer_contract_types_guide/ |
Thank you for your quick answer. Unfortunately, I read the link, and follow some guides, however, it did not work. As your answer, I tried: Then, I tried with the link's answer like: This does not occur any errors on it, however, the "no parameter" problem still occurs. ![]() I think with your comment, the error may occur because the type did not set from contract ABI. However, my ABI file was extracted by "Remix" and it is saved in ![]() ![]() By the way, the problem is still bothering me. |
Interesting case. The problem is you read the file (not import) and then convert it to const. I will investigate it. |
@hubts 2 option: type MyAbi = readonly [{
inputs: [
{
internalType: 'address';
name: 'to';
type: 'address';
},
{
internalType: 'uint256';
name: 'amount';
type: 'uint256';
},
];
name: 'transfer';
outputs: [
{
internalType: 'bool';
name: '';
type: 'bool';
},
];
stateMutability: 'nonpayable';
type: 'function';
}];
const abi = JSON.parse(fs.readFileSync('./ERC20Token.json', 'utf-8')).abi as unknown as MyAbi;
const contract = new Contract(abi);
contract.methods.transfer('0xe4beef667408b99053dc147ed19592ada0d77f59', 12); |
I encountered the same problem |
Hello @rickiey , |
Hello, @avkos Option 1. Declaring a JSON file as a variable doesn't seem to work. Like the link, it was declared as a Unfortunately, still not accepting argument. Option 2. Creating an ABI type works for now. I declared the Thank you for solving my problem. Option 1 did not work by declaring a One thing I'm curious about is that if I do this, after I implement a contract, I will not only make the ABI json, but also copy to declare as a type. There is no exact value from type, so I should read the JSON file to get value. This means that I need to manage and match the two files, ABI json file (value) and ABI typescript file (type). Is this the right way? Anyway, this problem has been solved and I can continue the project! |
For Angular and React typescript projects the issue is still active, with a workaround as outlined above. Additional steps still required - to extract the abi from a contract JSON artefact and manually assign as const fooAbi = [ xxx ] as const within your code. Would be great if we could find a more seamless solution for typescript frameworks to pull directly from the full JSON contract file and avoid the extra manual work per contract. |
Same problem, fixed it by using 'as const' at the abi. |
tried with viem.sh but getting same error:
|
Expected behavior
web3.eth.Contract.methods.myMethod(myParam)
works with parameters.Actual behavior
web3.eth.Contract.methods.setSystemAddress(address)
does not allow the parameter (see the below image).You need 0 arguments, but you got 1 argument.
.Steps to reproduce the behavior
web3.eth.Contract
whatever you have to generateContract
.web3.eth.Contract.methods.yourMethod
with some parameters.Logs
Sorry, the compile cannot be processed, any error logs cannot be provided.
Environment
yarn
(classic v1) package managerNestJS
boilerplate with Node.js version19.16.1
(also in16.15.1
)web3
package with version4.0.2
(maybe recent version)The text was updated successfully, but these errors were encountered: