2

Given this constructor:

function Voting(bytes32[] candidateNames) public {
    candidateList = candidateNames;
}

How to pass pass the value in the parameter candidateNames when I deploy the contract in remix?

enter image description here

  • 1
    What did you try? Did you try entering any value in the textbox infront of Deploy? – Achala Dissanayake Jun 3 '18 at 12:57
  • yes i am giving candidateName but it gives an error. – Rohit Sahu Jun 3 '18 at 15:09
  • Can you please update the question with what you tried and what is the error you got? – Achala Dissanayake Jun 3 '18 at 15:49
  • Rohit Sahu try it by using hexadecimal notation. means to say include 0x with input. i think it'll run. so try it. – San Ayush Aug 21 '18 at 18:25
  • Can you edit your answer and add an example of the input? Remember that the constructor parameter is an array. – Ismael Aug 22 '18 at 3:25
2

If you're willing to do a little text editing, here's a mostly painless way. Make new a contract (or temporarily add the function below to this contract and pass [] to the constructor when you run it). Hardcode the candidate names (note that I set the array size to 3 since I know it for this example):

function getBytes32ArrayForInput() pure public returns (bytes32[3] b32Arr) {
    b32Arr = [bytes32("candidate1"), bytes32("c2"), bytes32("c3")];
}

Compile and run the function. You should get this output:

0x63616e6469646174653100000000000000000000000000000000000000000000,0x6332000000000000000000000000000000000000000000000000000000000000,0x6333000000000000000000000000000000000000000000000000000000000000

Then use a text editor to format it like this:

["0x63616e6469646174653100000000000000000000000000000000000000000000","0x6332000000000000000000000000000000000000000000000000000000000000","0x6333000000000000000000000000000000000000000000000000000000000000"]

It's now in the proper format so that Remix will accept it in the constructor text field as bytes32[].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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