0

I am using web3.js 0.20.6 and I want to unlock an account to execute a smart contract method on a private blockchain. The account is used to pay for the gas. I have used the following code to unlock the account:

web3_1.personal.unlockAccount(web3.eth.accounts[0],password,time, function(error,result){
    if (result){
        // account unlocked so call smart contract function
        contract_instance.publishNode(param1, param2,{from:web3.eth.accounts[0],gas:300000});
    }
});

and I get the following error:

/home/davide/WebApp/node_modules/web3/lib/web3/requestmanager.js:61
    throw errors.InvalidResponse(result);
    ^

Error: account is locked
at Object.InvalidResponse (/home/davide/WebApp/node_modules/web3/lib/web3/errors.js:38:16)
at RequestManager.send (/home/davide/WebApp/node_modules/web3/lib/web3/requestmanager.js:61:22)
at Eth.send [as sendTransaction] (/home/davide/WebApp/node_modules/web3/lib/web3/method.js:145:58)
at SolidityFunction.sendTransaction (/home/davide/WebApp/node_modules/web3/lib/web3/function.js:167:26)
at SolidityFunction.execute (/home/davide/WebApp/node_modules/web3/lib/web3/function.js:253:37)
at Object.exports.publish_node (/home/davide/WebApp/red5Network.js:117:16)
at Object.callback (/home/davide/WebApp/app.js:61:16)
at /home/davide/WebApp/node_modules/web3/lib/web3/method.js:142:25
at /home/davide/WebApp/node_modules/web3/lib/web3/requestmanager.js:89:9
at XMLHttpRequest.request.onreadystatechange (/home/davide/WebApp/node_modules/web3/lib/web3/httpprovider.js:118:13)

On the other end if instead of calling a smart contract function I send ether from an account to another everything works. What is the issue?

  • can you say exactly what request does throw the error log you posted? – Kaki Master Of Time Apr 2 '18 at 13:50
  • @MedMansour I added the Smart contract call that throws the error – David Apr 2 '18 at 14:16
  • Are you sure the unlockAccount worked correctly? Because you do not check the error returned. Another possibility is that timeout value is too low. – Ismael Apr 2 '18 at 19:42
  • @Ismael I have just tried and error is null while result is true. The unlockAccount works when sending ether to another account as I can see the mined transaction and the new balances. I have setup also the default account to be eth.accounts[0] but I am still not able to call smart contract functions. I also tried to specify the timeout=15000 but it still does not work – David Apr 2 '18 at 19:52
0

Are you sure, you can use callback for this method? I am not aware of it. Try this code to figure out if it works:

try {
      web3.personal.unlockAccount(acc, pass);
    } catch(err) {
      return false;
    }
  • I get the same error – David Apr 2 '18 at 15:05
  • OK... Check permissions, which you have set. It should include these: --rpcapi eth,web3,personal – Vanja Dev Apr 3 '18 at 9:49
  • I was already using those options. I am starting geth with this command: ./geth identity "1" --datadir /home/.../path-to-datadir --networkid 4999 --rpc --rpcport 40901 --rpcapi db,eth,net,web3,shh,personal --rpccorsdomain "*" --port 30303 --nodiscover --shh I have tried to use different versions of geth but I still get the same error – David Apr 3 '18 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.