【问题标题】:Is there a way to access the account used for the deployment process in Ganache?有没有办法访问在 Ganache 中用于部署过程的帐户?
【发布时间】:2020-10-27 10:08:20
【问题描述】:

我正在构建一个去中心化的应用程序,嵌入式智能合约包含一个函数,该函数只能由智能合约的所有者(即启动部署过程的帐户)调用。我正在使用 Ganache,它带有 10 个预定义帐户。据我所知,用于部署的地址是该帐户列表中的第一个地址,因此我使用 web3.eth.getAccounts() 返回的第一个地址作为参数调用该函数。但有一个问题。当我从 Metamask 更改帐户时,web3.eth.getAccounts() 更改其值,第一个地址是 Metamask 中的地址。如何在不使用 web3.eth.getAccounts() 的情况下获取用于部署的帐户?

【问题讨论】:

    标签: blockchain solidity truffle ganache decentralized-applications


    【解决方案1】:

    只需从您想要的 ganache 中复制并粘贴地址。部署合约的最上面列出的地址

    web3.eth.sendTransaction({ to: "0xc25903033606D6D9FeE655E58F024b152B1734C1", from: '0x2fbFa394f462755a1c5c68eB4cee47b243046afc'})
    

    【讨论】:

      猜你喜欢
      • 2019-08-14
      • 1970-01-01
      • 2022-07-18
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 2021-03-14
      • 2020-09-24
      相关资源
      最近更新 更多