简体   繁体   English

如何在ganache / truffle / web3中解锁合同地址,以便我可以使用from作为调用函数?

[英]How to unlock a contract address in ganache/truffle/web3 so that I can use it as from to call a function?

I am building an altcoin contract using zeppelin library to make it upgradeable using a proxy. 我正在使用zeppelin库构建altcoin合同,以使其可以使用代理进行升级。 I also use a Ownable cotract that allows me to pass ownership to another address in 2 phases. 我还使用了一个Ownable合同,该合同允许我分两个阶段将所有权转移到另一个地址。 Transfer Ownership with the address as param and Claim Ownership which must be called with the previously address. 使用参数地址和所有权声明转移所有权,必须使用先前的地址进行调用。 I am using Ganache app on ubuntu, having 10 unlocked accounts. 我正在ubuntu上使用Ganache应用,有10个未锁定帐户。 The issue lays in this code: 问题在于以下代码:

Coin.deployed().then(coin => {
    TokenProxy.deployed().then(function(proxy) {
      coin.transferOwnership(proxy.address, {from:owner}).then(function(res) {
            proxy.claimOwnership({from: proxy.address}).then(function (res) {
              console.log("Done!");
            }).catch(function (e) {console.log(e);});
          }).catch(function (e) {console.log(e);});
        })
      })

The problem is that the proxy address will not be one of those 10 in the list so I end up with 问题是代理地址不会是列表中的10个地址之一,所以我最终得到

Error: sender account not recognized 错误:无法识别发件人帐户

Basically I am not sure if it's part of the ganache node(but if it is, for sure it is locked). 基本上我不确定它是否是ganache节点的一部分(但是如果是,请确保它已锁定)。 I tried to unlock it using web3 and a couple off different things. 我尝试使用web3和一些不同的东西解锁它。 Nothing helped. 没有任何帮助。 Ty. TY。

我认为错误在于您使用的是智能合约地址,而不是有效的以太坊钱包帐户。

Unlocking a contract account is not possible not only on Ganache but on the rest of the networks as well. 不仅在Ganache上,而且在其他网络上,都无法解锁合同帐户。 You cannot send a transaction with the contracts address as the from address since you do not have the private key for that address. 您不能使用合同地址作为发件人地址发送交易,因为您没有该地址的私钥。 If you could just unlock the contract's address what is there to stop someone from unlocking your address. 如果您可以解锁合同的地址,那将阻止他人解锁您的地址。

If you wish to call a function from a contract's address you have to call the function you wish to call from within the contract itself. 如果您希望从合同的地址调用函数,则必须从合同本身内部调用要调用的函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM