đManaging Accounts
WARNING: It's important to safely store and remember your password!
If you lose the password you use to encrypt your account, you will no longer be able to access that account. To reiterate, it is NOT possible to access your account without a password, and there is no forgot my password option.
The Ethereum CLI geth
provides account management via the account
command:
Manage accounts lets you create new accounts, list all existing accounts, import a private key into a new account, migrate to newest key format, and change your password.
It supports interactive mode, when you are prompted for password as well as non-interactive mode where passwords are supplied via a given password file. Non-interactive mode is only meant for scripted use on test networks or known safe environments.
Make sure you remember the password you gave when creating a new account (with new, update or import). Without it you are not able to unlock your account.
Note that exporting your key in unencrypted format is NOT supported.
Keys are stored under <DATADIR>/keystore
. Make sure you backup your keys regularly! See DATADIR backup & restore for more information. If custom datadir and keystore options are given, then the keystore option takes preference over the datadir option.
The newest format of the keyfiles is: UTC--<created_at UTC ISO8601>-<address hex>
. The order of accounts when listing is lexicographic, but as a consequence of the timespamp format, it is actually order of creation
It is safe to transfer the entire directory or the individual keys therein between Ethereum nodes. Note that in case you are adding keys to your node from a different node, the order of accounts may change. So make sure you don't rely or change the index in your scripts or code snippets.
And again. DO NOT FORGET YOUR PASSWORD
You can get info about subcommands by geth account <command> --help
.
Accounts can also be managed via the Javascript Console
Examples
Interactive use
creating an account
Listing accounts in a custom keystore directory
Import private key into a node with a custom datadir
Account update
Non-interactive use
You supply a plaintext password file as argument to the --password
flag. The data in the file consists of the raw characters of the password, followed by a single newline.
Note: Supplying the password directly as part of the command line is not recommended, but you can always use shell trickery to get round this restriction.
Creating Accounts
Creating a New Account
Creates a new account and prints the address.
On the console, use:
The account is saved in encrypted format. You must remember this passphrase to unlock your account in the future.
For non-interactive use the passphrase can be specified with the --password
flag:
Note: this is meant to be used for testing only; we don't recommend saving your password within a computer file or exposing it in any other way
Creating an Account by Importing a Private Key
Imports an unencrypted private key from <keyfile>
and creates a new account and prints the address.
The keyfile is assumed to contain an unencrypted private key as canonical EC raw bytes encoded into hex.
The account is saved in encrypted format, you're prompted to enter a passphrase. You must remember this passphrase to unlock your account in the future.
For non-interactive use the passphrase can be specified with the --password
flag:
Note: since you can directly copy your encrypted accounts to another Ethereum instance, this import/export mechanism isn't needed when you transfer an account between nodes.
Warning: when you copy keys into an existing node's keystore, the order of accounts you are used to may change. Therefore, make sure you either don't rely on the account order or doublecheck and update the indexes used in your scripts.
Warning: if you use the password flag with a password file, it's best to make sure the file is not readable or even listable for anyone but you. You achieve this with:
Updating an Existing Account
You can update an existing account on the command line with the update
subcommand with the account address or index as parameter. You can specify multiple accounts at once.
The account is saved in the newest version in encrypted format, and you'll then be prompted to enter a passphrase to unlock the account and another to save the updated file.
This same command can therefore be used to migrate an account of a deprecated format to the newest format or change the password for an account.
After a successful update, all previous formats/versions of that same key are removed!
Importing Your Presale Wallet
Importing your presale wallet is very easy. If you remember your password that is:
It will then prompt you for your password and imports your Ethereum presale account. It can be used non-interactively with the --password option taking a passwordfile as argument containing the wallet password in cleartext.
Listing Accounts and Checking Balances
Listing your current accounts
From the command line, call the CLI with:
to list your accounts in order of creation.
Note: This order can change if you copy keyfiles from other nodes, so make sure you either don't rely on indexes or (if you copy keys) check and update your account indexes in your scripts.
When using the console:
or via RPC:
If you want to use an account non-interactively, you need to unlock it. You can do this on the command line with the --unlock
option which takes a comma separated list of accounts (in hex or index) as argument so you can unlock the accounts programmatically for one session. This is useful if you want to use your account from dApps via RPC. --unlock
will unlock the first account. This is useful when you created your account programmatically; you don't need to know the actual account to unlock it.
Create account and start node with account unlocked:
Instead of the account address, you can use integer indexes which refers to the address position in the account listing (and corresponds to order of creation)
The command line allows you to unlock multiple accounts. In this case the argument to unlock is a comma delimited list of accounts addresses or indexes.
If this construction is used non-interactively, your password file will need to contain the respective passwords for the accounts in question, one per line.
On the console you can also unlock accounts (one at a time) for a duration (in seconds).
Note that we do NOT recommend using the password argument here, since the console history is logged, so you may compromise your account. You have been warned.
Checking account balances
To check your the etherbase account balance:
Print all balances with a JavaScript function:
That can then be executed with:
Since this function will disappear after restarting geth, it can be helpful to store commonly used functions to be recalled later. The loadScript function makes this very easy.
First, save the checkAllBalances()
function definition to a file on your computer. For example, /Users/username/gethload.js
. Then load the file from the interactive console:
The file will modify your JavaScript environment as if you has typed the commands manually. Feel free to experiment!
Last updated