3

Need to unlock account to call contracts functions on client side. So i need to use web 3 or web 3 extanded. But it doesn't work.Method are not availebly. Maybe you know some others ways how to call function specially in IOS-app.

1

3 Answers 3

2

You can invoke the unlockAccount method of personal from your Web application. I am using Web3 0.18.2 version.

In the below mentioned method call last parameter is duration i.e how long the account will be kept unlocked in seconds. It is optional. You can use any of the ways.

When you start your node using Geth you need to expose personal through rpc. I use this parameter "--rpcapi "db,eth,net,web3,personal". Although it is not recommended to expose personal over rpc.

Code Sample
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); web3.personal.unlockAccount("(account address)", "(pass phrase)");

web3.personal.unlockAccount("(account address)", "(pass phrase)", 500);

2
  • I need to do client version so I need to do this in pure NODEjs
    – Vladimir
    Commented Apr 5, 2017 at 12:25
  • Added the line to populate the web3 object which I believe will be a generic call.
    – Susmit
    Commented Apr 5, 2017 at 12:42
1

It's simple,just type this command in the geth console:

web3.personal.unlockAccount("0x..", "<pass>");
0

maybe something along those lines:

function unlockAccount(val) {
var accounts = web3.eth.coinbase;
var passphrase = val;
if(passphrase !=null){
web3.personal.unlockAccount(web3.eth.coinbase, passphrase,1000, function (error, result){
    if(error){
    var str =error.toString();
    if(str.includes("could not decrypt")){
        bootbox.hideAll();
        document.getElementById("loading").style.display = "none";
        document.getElementById("successAlert").style.display = "none";
        if(document.getElementById("dangerAlert")){
            document.getElementById("dangerAlert").style.display = "none";
        }
        bootbox.alert("Please enter the valid Passphrase.! ");
    }
    }
  });
 }
}

we are using this JS to unlock an account before calling functions of smart contracts etc...

/B

6
  • If i do this in NodeJS(truffle console). When i try web3.personal.unlockAccount i have Error: Method are not availeble or not exist
    – Vladimir
    Commented Apr 5, 2017 at 12:33
  • Believe you have not included the personal lib rpcapi param due to which it is not able to access. Can you share the whole geth command you are invoking
    – Susmit
    Commented Apr 5, 2017 at 15:03
  • Sorry but dont use geth at all. I have private blockchain on Axure and connect to him in nodejs. With pure web3 or web3extended.
    – Vladimir
    Commented Apr 6, 2017 at 11:31
  • I think the question was how the geth-node on Azure was started. You can add modules and switches starting geth...
    – Borinho
    Commented Apr 6, 2017 at 11:38
  • Borinho, what modules should I add in Azure-node and how?
    – Vladimir
    Commented Apr 6, 2017 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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