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.
3 Answers
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);
It's simple,just type this command in the geth console:
web3.personal.unlockAccount("0x..", "<pass>");
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
-
If i do this in NodeJS(truffle console). When i try web3.personal.unlockAccount i have Error: Method are not availeble or not exist– VladimirCommented 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– SusmitCommented 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.– VladimirCommented 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...– BorinhoCommented Apr 6, 2017 at 11:38
-