Solidity

將乙太幣從賬戶轉移到合約的問題

  • March 23, 2017

這是我用來傳輸 ethets 的函式:

function addBalance(address beneficiary) payable returns(bool success){ if (beneficiary.send(msg.value)) throw; return true; }

使用 web3 呼叫函式:

contract.addBalance.sendTransaction(contractAddress, 
       {from: senderAddress, to: contractAddress, gas:1000000, value: web3.toWei(7, "ether")},function (error, result){ 
           if(!error){

               } else{
                   console.log(error);
               }
       });

要麼

contract.addBalance.sendTransaction(contractAddress, 
       {from: web3.eth.accounts[5], to: contractAddress, gas:1000000, value: web3.toWei(7, "ether")},function (error, result){ 
           if(!error){
               } else{
                   console.log(error);
               }
       });

當我呼叫它時,它給出了錯誤說:

Error: authentication needed: password or unlock
at Object.InvalidResponse (errors.js:35)
at requestmanager.js:86
at XMLHttpRequest.request.onreadystatechange (httpprovider.js:118)

我已經解鎖了我的帳戶如果我用 coinbase 地址更改發件人地址,它可以正常工作,但不能使用任何其他帳戶地址

工作正常的電話如下:

contract.addBalance.sendTransaction(contractAddress, 
       {from: web3.eth.coinbase, to: contractAddress, gas:1000000, value: web3.toWei(7, "ether")},function (error, result){ 
           if(!error){

               } else{
                   console.log(error);
               }
       });  

您必須解鎖發送乙太幣的帳戶:

personal.unlockAccount(eth.accounts[0])

geth並在控制台中插入密碼。

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