1

I have a Truffle migration that looks something like this;

var MyContract = artifacts.require("./MyContract.sol");
module.exports = function(deployer) {
  deployer.deploy(MyContract,[
    {
      "title": "President",
      "choices": [
        {"name": "Mary", "votes": 10},
        {"name": "Maria", "votes": 10},
        {"name": "Maryam", "votes": 10}
      ]
    },
    {
      "title": "Vice President",
      "choices": [
        {"name": "John", "votes": 10},
        {"name": "Juan", "votes": 10},
        {"name": "Abdullah", "votes": 10}
      ]
    }
  ], {gas: 2900000});
};

And MyContract.sol looks like this;

contract MyContract {
  // Define some public variables here...  
  function MyContract(bytes32[] myArray) { // Not sure this line is right
    // How do I access constructor arguments here?
  }
}

The problem is, I don't know what Truffle translates my constructor arguments to in Solidity. I know I need to tell the constructor what type of data to expect, but I don't know what that data will look like, or what syntax to use to access it. The deployer docs are on the Truffle website, but they only explain that you can pass the arguments, not how to access them in Solidity.

Edit: It looks like the JSON interface that truffle-contract uses might be a piece of the puzzle. interface.abi is an array that contains this element for the constructor;

{
  "inputs": [
    {
      "name": "myArray",
      "type": "bytes32[]"
    }
  ],
  "payable": false,
  "type": "constructor"
}
2

1 Answer 1

0

I meet same problem, fortunately I got answer in the following link: 'Error: invalid arrayify value (argument="value", value="", code=INVALID_ARGUMENT, version=bytes/5.0.5)\n'

I see you want to pass an btyes[] type parameter, in javascript, it should be a array of hex string, for example:

var myArray = ["0x00", "0x00", ..., "0x00"] 

The content of array is what you want to pass to function in hex string type

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Aug 2, 2022 at 10:06

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.