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"
}

Your Answer

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

Browse other questions tagged or ask your own question.