DeXit Network
Search…
⌃K
Links

New accounts

New accounts can be generated using the Javascript console using personal.newAccount(). A new password is requested in the console and successful account creation is confirmed by the new account address being displayed
personal.newAccount()
Accounts can also be created by importing private keys directly in the Javascript console. The private key is passed as an unencrypted hex-encoded string to personal.importRawKey() along with a passphrase that will be used to encrypt the key. A new key file will be generated from the private key and saved to the keystore.
personal.importRawKey("hexstringkey", "password")

Listing accounts

The accounts function in the eth namespace can be used to list the accounts that currently exist in the keystore.:
eth.accounts
or alternatively the same is achieved using:
personal.listAccounts
This returns an array of account addresses to the terminal.

Unlocking accounts

To unlock an account, the personal.unlockAccount function can be used:
personal.unlockAccount(eth.accounts[1])
The account passphrase is requested:
Unlock account 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b
Passphrase:
true
​
This unlocked account can now be used to sign and send transactions. it is also possible to pass the passphrase as an argument to personal.unlockAccount() along with a duration after which the accout will automatically re-lock (in seconds), as follow
personal.unlockAccount(eth.accounts[1], "passphrase", 60)
This unlocks the account for 60 seconds. However, this is not recommended because the command history is logged by the Javascript console which could compromise the security of the account. An unlocked account can be manually re-locked using personal.lockAccount(), passing the address as the sole argument.

Unlocking for transactions

Sending transactions from the Javascript console also requires the sender account to be unlocked. There are two ways to send transactions: eth.sendTransaction and personal.sendTransaction. The difference between these two functions is that eth.sendTransaction requires the account to be unlocked globally, at the node level (i.e., by unlocking it on the command line at the start of the Geth session). On the other hand, personal.sendTransaction takes a passphrase argument that unlocks the account temporarily in order to sign the transaction, then locks it again immediately afterwards. For example, to send 5 ether between two accounts in the keystore:
var tx = {from: eth.accounts[1], to: eth.accounts[2], value: web3.toWei(5, "ether")}
​
# this requires global account unlock for eth.accounts[1]
eth.sendTransaction(tx)
​
# this unlocks eth.accounts[1] temporarily just to send the transaction
personal.sendTransaction(tx, "password")

Summary

This page has demonstrated how to use Geth’s built-in account management tools, both on the command line and in the Javascript console. Accounts are stored encrypted by a password. It is critical that the account passwords and the keystore directory are safely and securely backed up.
​