【问题标题】:Deploy a smart contract with constructor in Truffle在 Truffle 中使用构造函数部署智能合约
【发布时间】:2020-11-14 17:33:12
【问题描述】:

我想部署我的合约,其中包含一个构造函数(2 个账户地址和一个值 P),在 Remix 中,我手动输入了账户地址和 P 值,但在松露中,我手动编辑了 2_deploy_contracts.js 文件如下:

合同:

constructor(address payable _account1, address payable _account2, uint _P) public {account1 = _account1;account2 = _account2; P = _P;}

2_deploy_contracts.js:

var contract = artifacts.require("contract");
module.exports = function(deployer)  {
deployer.deploy(contract, account1, account2, P);};

提前感谢您的帮助。

【问题讨论】:

  • 你能澄清一下你的问题吗?
  • 合约部署了3个构造函数:account1的地址、account2的地址和P的值。在Remix中,我在部署合约之前手动输入了这些值。但是在 Truffle 中,我知道我必须设置 2_deploy_contracts.js 文件,我的问题就在这里。我如何在部署合约之前配置此文件,因为 Truffle 在迁移阶段向我显示错误。
  • 感谢@EmmanuelCollin。我已将它们声明为“var”,并且部署已成功完成。

标签: solidity smartcontracts truffle


【解决方案1】:

你必须声明和初始化这些参数:
var account1='0x...';
var account2='0x...';
var P=...;
deployer.deploy(contract, account1, account2, P);

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 2018-10-12
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    相关资源
    最近更新 更多