使用 truffle-hd-wallet 进行 Ropsten 部署的默认帐户

Default account for Ropsten deployment using truffle-hd-wallet

我正在尝试使用 truffle-hd-wallet 将自定义 ERC20 令牌部署到 Ropsten 网络。交易进行得很顺利,然而,奇怪的是新部署的自定义 ERC20 代币主持有人账户不是我想要的账户,而是一个未知账户。当我将令牌添加到我自己的 Ropsten 帐户时,金额为零,应该具有初始值。有没有办法可以将我想要的部署合同地址设置为松露?请指教。 谢谢。

Desire Address : 0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5

Actual Address : 0xEDD4C3676c8579D25463040fd196626a9B7C60a2

 ropsten: {
      provider: function() {
        return new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/" + INFURA_API_KEY, 0);
      },
      network_id: 3,
      gas: 4700000
    }
  },



module.exports = function(deployer) {
  deployer.deploy(CToken).then(function () {
    let walletA = walletAaddr;
    let walletB = walletBaddr;

    return deployer.deploy(
      CTokenSale,
      CToken.address,
      walletA,
      walletB
    ).then(function () {
        // token ownership setting
        CToken.deployed().then(function(instance) {
          let fptc = instance;
          return fptc.transferOwnership(CTokenSale.address, {gas:1000000});
        }).then(function(result) {
          console.log("transferOwnership successful!")
        }).catch(function(e) {
            console.log("Ownership Transfer failed!")
        });     


        CToken.deployed().then(function(instance) {
          let fptc = instance;
          return fptc.transfer(CTokenSale.address, 100, {gas:1000000});
        }).then(function(result) {
          console.log("Sales Token Ready!")
        }).catch(function(e) {
            console.log("Sales Token failed to deploy!")
        });


    }); 
  });
};

您还没有包含您的代币智能合约代码。我假设部署代币的帐户获得了初始供应,或者具有铸币者角色。

我建议您确认从您的 12 字助记词(助记词)派生的第一个帐户是您想要的地址:例如0xd61794624e9542495A72Cfac7Cc10B4275b8f8E5。 您将第一个帐户指定为 0 作为 address_index

使用 Truffle HDWallet Provider,如果您使用的不是默认路径,您可以指定派生路径。 https://github.com/trufflesuite/truffle/tree/develop/packages/truffle-hdwallet-provider

我建议阅读 OpenZeppelin 文档(如果您还没有):

您也可以在以下网址提问: