1

I'm trying to test out some sample code for voting in Solidity. What I wanted to try out is if I am able to pass the names of the candidates (as strings) as arguments to the constructor.

The program deploys, but when I try to put in some sample strings as input, it shows this error:

creation of Voting errored:

 Error encoding arguments: Error: types/values length mismatch (count={"types":1,"values":3}, value={"types":["string[]"],"values":["Sam"," Andrew"," Ben"]}, code=INVALID_ARGUMENT, version=abi/5.5.0)

Is there something wrong with the way I pass the arguments (see screenshot below), or is a string array not supported?

Would very much appreciate any advice! Thanks!

enter image description here

1 Answer 1

0

You're currently giving arguments like this:

"Sam", "Andrew", "Ben"

This works for a constructor like:

constructor(string memory name1, string memory name2, string memory name3)

But your constructor is:

constructor(string[] memory name)

To provide input arguments for your constructor, use this format:

["Sam", "Andrew", "Ben"]

This way, you pass an array with the strings, not separate strings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.