| 知乎专栏 | 多维度架构 |
在 Truffer 中部署构造方法需要参数传递例子如下,MyContract 需要传递参数 _name:
pragma solidity ^0.4.19;
contract MyContract {
string name;
function MyContract(string _name) public{
name = _name;
}
function getName() public view returns (string) {
return name;
}
}
migrations/3_initial_migration.js
var MyContract = artifacts.require("./MyContract.sol");
module.exports = function(deployer) {
deployer.deploy(MyContract,"Netkiller");
};
给构造方法传递变量的方法是 deployer.deploy(MyContract,arg1, arg2, ...); arg1 是传递的参数。
多个合约传递方法是:
deployer.deploy([ [ContractA, arg1, arg2, ...], ContractB, [ContractC, arg1] ]);