知乎專欄 | 多維度架構 | | | 微信號 netkiller-ebook | | | QQ群:128659835 請註明“讀者” |
在 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] ]);