6

I have a script that I run with geth attach, and then I use:

primary = eth.accounts[0];
personal.unlockAccount(primary, "password");

like I saw in the example script.

Doing this in geth usually takes about one or two seconds. I learned there was another way to unlock accounts. I was wondering if it was faster to unlock directly with geth --unlock "0xaddress" --password "password" attach. What does it do differently ?

How can I know if it unlocked successfully ? If I use a random address or password instead of the correct ones, attach still opens correctly.

EDIT: I found in the answer of a duplicate question that you can't use --unlock with attach, which wasn't in the original answer (or at least not clearly).

Geth attach "opens correctly" because it ignores those flags. You can run geth --unlock "0xaddress" --password "password" attach or geth --password --testnet --testnet attach and it will open like geth attach (flag order seems to be important sometimes though, you can't use password after testnet or it ignores attach).

Teleporting Goat
  • 1,516
  • 1
  • 13
  • 33

1 Answers1

3

--unlock also takes a second, no benefit here. On the other hand, not showing your password on the command line is a net benefit. Yes, make it --password password_file.txt instead of plain password in the command.

If it failed to decrypt, then Geth will exit with error code 1:

$ geth --unlock "0" --password password_file.txt
...
Fatal: Failed to unlock account 0 (could not decrypt key with given passphrase)
$ echo $?
1