[Ethereum] How to deploy contracts that take parameters in their initialisers using Truffle?


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?

Best Answer

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