2

I have a constructor like so:

constructor(bytes32[] proposalNames) public {
...

How do I input values for it on deplyoment with remix? I tried ["foo", "bar"] but it said:

creation of Ballot errored: Error encoding arguments: Error: invalid bytes32 value (arg="", coderType="bytes32", value="foo", version=4.0.47)

1
  • 1
    That's because foo and bar aren't bytes32 arguments. Use something like: ["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002"]
    – alberto
    Commented Oct 20, 2020 at 16:06

1 Answer 1

6

This:

const Web3 = require("web3");

console.log(Web3.utils.asciiToHex("foo"));
console.log(Web3.utils.asciiToHex("bar"));

Gives:

0x666f6f
0x626172

So I believe that one of the following should work for you:

[0x666f6f, 0x626172]
["0x666f6f", "0x626172"]
[0x666f6f0000000000000000000000000000000000000000000000000000000000, 0x6261720000000000000000000000000000000000000000000000000000000000]
["0x666f6f0000000000000000000000000000000000000000000000000000000000", "0x6261720000000000000000000000000000000000000000000000000000000000"]
1
  • 2
    Thanks - interestingly only the last one worked.
    – nz_21
    Commented Oct 20, 2020 at 16:57

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.