Contract-Development

如何將帳戶地址傳遞給 truffle deployer?

  • April 2, 2022

在使用 truffle 遷移進行部署時,如何將我的帳戶地址傳遞給合約建構子?我想將地址傳遞到MyAdress如下所示。

deployer.deploy(MyContract, MyAddress)

我的契約是這樣的

address payable public admin;
constructor(address payable _admin) {
       admin = _admin;
}

您需要在部署文件中將地址定義為常量:

const MyAddress = '0x123...'

deployer.deploy(MyContract, MyAddress)

參考地址到 truffle 配置文件更合適。

module.exports = async function(deployer, network, accounts) {
 const deployerAddress = accounts[0];
 await deployer.deploy(Contract, deployerAddress);
};

引用自:https://ethereum.stackexchange.com/questions/70232