12

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?

ThePiachu
  • 562
  • 1
  • 6
  • 14

1 Answers1

21

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);

};
pabloruiz55
  • 7,686
  • 2
  • 17
  • 38
  • 1
    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: https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/examples/SampleCrowdsale.sol 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 03 '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 03 '18 at 14:15