Truffle Contract Deployment – Passing Constructor Parameters

contract-deploymentethereum-wallet-dapptestrpctruffle

I am using testrpc and truffle for deploying contracts.I want to pass constructor parameters while deploying.

    contract User { 
          string public userName;

          function User(string _name) {
                 userName=_name;
          }

   }

I am using contractname.deployed() for deploying contract.

      var user=User.deployed()

This deployment command won't initializes the userName parameter.

How to pass _name to this contract using truffle?

Best Answer

In Truffle, constructor params go in /migrations. So, something like:

deployer.deploy(User, "foo");

User.deployed() will be a User contract that was deployed with _name="foo"

Related Topic