简体   繁体   中英

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. I also use a Ownable cotract that allows me to pass ownership to another address in 2 phases. 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. 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

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). I tried to unlock it using web3 and a couple off different things. Nothing helped. Ty.

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

Unlocking a contract account is not possible not only on Ganache but on the rest of the networks as well. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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