This is my code to send payment from my wallet to another wallet

var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
var addr = "0x...........................";
var pass = "thePassword#";
web3.eth.personal.unlockAccount(addr, pass);
const toAddress = withdrawalAddress; //address of the recipient
const amountToSend = 0000001233489520;//wei;
console.log("Amount in toWei : ", amountToSend);
var send = web3.eth.sendTransaction({from:addr,to:toAddress, value:amountToSend});

This code works fine and make payment successfully. But sometimes it give me error Error: Returned error: authentication needed: password or unlock

Since it works fine with same code and gives error with same code. Why this?

  • I think there is an extra parameter in web3.eth.unlockAcount(addr,pass,dur) that determines how long the unlock last, probably that is causing the error eventually. – Jaime Mar 29 '18 at 14:30
  • how this parameter can be used? – shawn Mar 29 '18 at 15:32
  • web3.eth.personal.unlockAccount(address, password, 600) .then((response) => { console.log(response); }).catch((error) => { console.log(error); }); this is coming from: github.com/ethereum/web3.js/issues/986 In web3.py you can just use web3.eth.unlockAcount(addr,pass,dururation=none) – Jaime Mar 29 '18 at 16:08

Your Answer

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

Browse other questions tagged or ask your own question.