5

I'm trying to build a smart contract with Truffle. I can compile it just fine, but when I try to deploy it on the network, I don't get an option to pass in the initialiser parameters and thus the contract fails.

How do I pass the parameters to a Truffle-compiled contract during deployment?

14

In your 2_deploy_contracts.js file you can add parameters when deploying the contract:

var Contract = artifacts.require("./Contract.sol");

module.exports = function(deployer) {
  deployer.deploy(Contract,constructor_param_1, constructor_param_2, ,constructor_param_3, ,constructor_param_etc);

};
  • What if the contract argument is another contract? How is is provided in this deploy contracts file? For example I am trying to deploy this: github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/… How do I provide MintableToken _token – codesalsa Feb 23 '18 at 21:21
  • How can you pass an argument to the utility which executes 2_deploy_contracts.js (i.e., how can you pass an argument to truffle migrate or truffle deploy)? – goodvibration Oct 3 '18 at 14:04
  • Ha, found it. Just add it at the end of the truffle migrate command-line, and then in 2_deploy_contracts.js, access it via process.argv. – goodvibration Oct 3 '18 at 14:15

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