when I use the web3 interface to sign on msgs, it tell me that the account should be unlocked, how can I manage this with geth and what exactly does unlocking mean?
-
I tried this command geth --unlock "ACCOUNT_PUBLIC_ADDRESS" --password "PASSWORD" ang got the error: account unlock with http access is forbidden Then i tried to unlock account by typing this command personal.unlockAccount(eth.accounts[0], '1234' ,9000) on javascript console but still got the same error: account unlock with http access is forbidden– Haseeb AhmadSep 13, 2019 at 10:48
3 Answers
By default, your accounts in Geth are "locked," which means that you can't send transactions from them. You need to unlock an account in order to send transactions from it through Geth directly or via RPC (though web3 does not support this). In order to unlock an account, you'll need to provide the password, which is used to decrypt the private key associated with your account, hence allowing you to sign transactions.
With that being said, how do you unlock an account? There are a couple different ways you can do it, which are highlighted in the Geth documentation. I'll provide an overview:
Unlock account when you run Geth. The password parameter is optional. If you don't provide it, you'll be prompted to type in the password.
geth --unlock <YOUR_ACCOUNT_ADDRESS> --password <YOUR_PASSWORD>
Unlock account from the Geth interactive Javascript console. Again, the password is optional. If you don't provide it, you'll be prompted to type it in. Note that in earlier versions of Geth, providing the password as a parameter would cause the password to show up in the Geth log, which may be a security concern.
personal.unlockAccount(address, "password")
-
8It should be noted that entering the password non-interactivly stores the password in plaintext in the console history. This should really not be used as it opens up an attack vector.– tayvanoMay 22, 2016 at 2:06
-
1
geth --unlock
is the way to do it, i guessweb3
will log all of your inputs in log– niksmacMay 22, 2016 at 3:18 -
3remove the brackets, then it should work:
geth --unlock 0x3b3F14690C8Fb8b1B333Ff38961bdEEa658a3873
Not that this is prompting you for a password and the prompt for the password might be hidden somewhere in the mass of output during geth startup, e.g.Unlocking account 0xb2... | Attempt 1/3 Passphrase: I0522 12:30:46.360237 node/node.go:298] IPC endpoint opened: /home/someone/.ethereum/geth.ipc I0522 12:30:46.836509 p2p/nat/nat.go:111] mapped network port tcp:30303 -> 30303 (ethereum p2p) using UPNP IGDv1-IP11
(Try to find the wordPassphrase
in the above output ;) ) May 22, 2016 at 10:32 -
2
-
2@bshea Note that if you wish to use the automatic relock but don't want to pass your password as a parameter, you can also use
personal.unlockAccount("address", undefined, 300)
– NulanoApr 4, 2018 at 15:43
Just to add to the excellent accepted answer.
You can also unlock the account from Web3 directly:
web3.personal.unlockAccount('0xE0ca...c1f7', 'mypass')
And lock it back:
web3.personal.lockAccount('0xE0ca...c1f7')
For more details refer to the web3-eth-personal
module.
what exactly does unlocking mean?
A Geth node implementation contains built-in account management, that is, it maintains the account's private key, which is stored on disk in encrypted form. Unlocking an account means decrypting its private key and storing it in memory (it is never stored decrypted on disk).
⚠ This means you should take extra care not to allow anyone access your Geth node via HTTP-RPC, WS-RPC or IPC, because these interfaces allow transferring ether from any unlocked account! ⚠