Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use the unlockAccount method? #986

Closed
yibai567 opened this issue Aug 16, 2017 · 20 comments
Closed

How do I use the unlockAccount method? #986

yibai567 opened this issue Aug 16, 2017 · 20 comments

Comments

@yibai567
Copy link

the doc is ....
// TODO
getAccounts, unlockAccount, lockAccount, sendTransaction, ecRecover

@SidhMj
Copy link

SidhMj commented Aug 25, 2017

in stackexchange they says web3.personal.unlockAccount("0x..", "", 1000); Please test and report if this works with web3 1.0 beta .18 . I am also facing this issue.
I also asked something like this

@rsbombard
Copy link

I've tested this on web3 1.0-beta 18 and can confirm it works with the following code. The only difference is the call chaining, it's web3.eth.personal instead of web3.personal.

web3.eth.personal.unlockAccount(address, password, 600)
	.then((response) => {
		console.log(response);
	}).catch((error) => {
		console.log(error);
	});

@ghost
Copy link

ghost commented Sep 19, 2017

the previous code throws an error for me for "web3": "^1.0.0-beta.20":

Error: Returned error: The method personal_unlockAccount does not exist/is not available
    at Object.ErrorResponse (/Users/serge/repos/learning/learning_npm_web3/node_modules/web3/packages/web3-core-helpers/src/errors.js:29:16)
    at /Users/serge/repos/learning/learning_npm_web3/node_modules/web3/packages/web3-core-requestmanager/src/index.js:137:36
    at XMLHttpRequest.request.onreadystatechange (/Users/serge/repos/learning/learning_npm_web3/node_modules/web3/packages/web3-providers-http/src/index.js:64:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/serge/repos/learning/learning_npm_web3/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:64:18)

@rsbombard
Copy link

@serge-nikitin

Make sure "personal" is enabled in the RPC/IPC API options when starting geth.

https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options

@yibai567
Copy link
Author

Thanks, I have to solve it

@SidhMj
Copy link

SidhMj commented Sep 20, 2017

web3.eth.personal.newAccount only returns true or false then how can I get the address of the created account using web3?

@alexpricedev
Copy link

@sidharthaA #1157 is going to resolve that.

@Suhail
Copy link

Suhail commented Jan 5, 2018

When you manually create an account, I get: "Error: Returned error: Error: could not unlock signer account"

How do you do this if you did web3.eth.accounts.create()? You get a account object back but you're not setting a password when you call that function.

@SidhMj
Copy link

SidhMj commented Jan 5, 2018

@Suhail The process is kind of tricky for now as per my knowledge
object = web3.eth.accounts.create() will create an account object but it will not get imported into your geth node.
To do that you need to do web3.eth.personal.importRawKey(privatekey, passphrase)
you will get the privatekey from object.privatekey
Now you can see your account from your geth console.
Note you need to give the exact passphrase at the time of unlocking the account.
object.address will return you the address.
@alexpriceonline I find this way of creating an account. Is this ok ?

@VikkiUser
Copy link

Hi all, I have a similar situation with creating new accounts and unlocking them.
Over IPC i call web3.personal.newAccount('qwerty123'), after it i have an address, private key and new file in keystore directory of geth so i suppose that it already have been imported to node.
After it i call method web3.personal.unlockAccount('0x602039bb4b8ec6bf9c49716f640edb9a47383483', 'qwerty123') and get error: Error: could not decrypt key with given passphrase What i can do wrong?
unlock.txt
create_address.txt

P.S. All this through nodejs
P.P.S. I am newbie in blockchain/ thanks.

@rushikeshacharya
Copy link

While starting the ethereum blockchain, make sure "personal" is enabled in the RPC/IPC API options

geth --datadir . console --rpc --rpcapi web3, personal,eth,network,db

@VikkiUser
Copy link

#HrishikeshFC Thanks for reply, i switch to rpc and php, and work well for now. Thanks again.

@jbarros35
Copy link

web3.eth.personal.newAccount('!@superpassword')
.then(console.log);

this is hard to believe that create not working... hard!

@SidhMj
Copy link

SidhMj commented Apr 9, 2018

@jbarros35 web3.eth.accounts.create() is working fine with that web3.eth.personal.importRawKey(privatekey, passphrase) method
And
web3.eth.personal.newAccount('!@superpassword').then((response) => {console.log(response)})
also working with no issue

@jbarros35
Copy link

Hi, I'm using web3 beta 33. Now I think its fine the issue is when we at first time install web3 it won't intall the beta.. they install 0.2.2

@stone212
Copy link

@VikkiUser You said "Thanks for reply, i switch to rpc and php, and work well for now. Thanks again." Can you please tell me how you handled unlocking and re-locking accounts using RPC?

@gerchicov-bp
Copy link

Uncaught TypeError: Cannot read property 'unlockAccount' of undefined
When I remove eth part in chain - I get:
inpage.js:1 Uncaught Error: The MetaMask Web3 object does not support synchronous methods like personal_unlockAccount without a callback parameter. See <link to web3.js documentation>
And of course the suggested link is totally useless.

Where can I see the full example with login into MetaMask? All the tutorials contain random chunks of code which look like normal but become a hell of nested code together.
Any description about how to use it with promises?

@VikkiUser
Copy link

Hi @stone212
$this->rpc->request('personal_unlockAccount', [$from, $psf])
$from - eth address
$psf - pass phrase

$this->rpc->request('personal_newAccount', [$psf])
$psf - pass phrase
All this using geth - latest version and CURL.
Hope this helps.

@yibai567
Copy link
Author

This demo is about the use of the unlockAccount method. The documentation is in Chinese, but the code is easy to understand。
https://github.com/WenHou/eth-web3-server

@crypto-sporidium
Copy link

Still confused by this..
In web3j

NewAccountIdentifier ac = node.personalNewAccount("secret").send();
String address = ac.getAccountId();

This works and a new account[6] is created on the node having address
However in java script console

personal.unlockAccount(eth.accounts[6],"secret",1000)
Error: could not decrypt key with given passphrase

Second connected issue when trying to transaction from created account.
webj3

Transfer.sendFunds( .... Credentials ..  ) requires credentials object
Credentials.create("< NEEDS PRIVATE KEY ??? ");

What is the relationship between personalNewAccount("secret") and privateKey as they appear to not be the same thing ? or how to generate privateKey from "secret" after account has already been created using the API with secret. once NewAccountIdentifier ac is not longer accessible ?

@nivida nivida closed this as completed Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests