Creating a Private Key โ
To participate in a blockchain network, such as issuing transactions, you need to create a private key. This private key allows you to secure your account and perform transactions using your unique key.
In Nine Chronicles, the blockchain technology is powered by Libplanet. Through the Libplanet.Tools project, you can use the planet
CLI to create a private key.
Installing the planet
CLI โ
First, refer to the README documentation for Libplanet.Tools
to install the planet
CLI.
๐ก
This tutorial uses version 5.0.0 of the planet
CLI.
Using planet key
โ
Letโs create a private key using the planet key
command. First, run the planet key
command to see the list of managed keys.
planet key
You should see something like this:
Key ID Address
------------------------------------ ------------------------------------------
Since no keys exist yet, the list is empty. Next, letโs check out the options available by running the planet key --help
command.
planet key --help
Youโll see the following output:
Usage: planet key [command]
Usage: planet key [--path <String>] [--help]
List all private keys.
Commands:
create Create a new private key.
remove Remove a private key.
import Import a raw private key or Web3 Secret Storage.
export Export a raw private key (or public key).
generate Generate a raw private key without storing it.
sign Sign a message.
derive Derive public key and address from private key.
Options:
--path <String> Specify key store path to list.
-h, --help Show help message
Now, letโs use the planet key create
command to generate a new private key.
๐จ
When creating a private key for actual use, make sure to use a strong passphrase.
planet key create
Youโll be prompted to enter a passphrase:
Passphrase: ***************
Retype passphrase: ***************
Key ID Address
------------------------------------ ------------------------------------------
1fd94a3e-2273-489b-bd44-b62036e2c07d 0xb4179Ad0d7565A6EcFA70d2a0f727461039e0159
After entering a passphrase, a new private key is created. The key is represented by a Key ID
and an Address
within the planet
CLI. Next, letโs export the private and public keys from this Key ID
. Run planet key export --help
to see the available options.
planet key export --help
Youโll see the following output:
Usage: planet key export [--passphrase <PASSPHRASE>] [--passphrase-file <FILE>] [--public-key] [--bytes] [--json] [--path <String>] [--help] key-id
Export a raw private key (or public key).
Arguments:
0: key-id A key UUID to export. (Required)
Options:
-p, --passphrase <PASSPHRASE> Take passphrase through this option instead of prompt. Mutually exclusive with --passphrase-file option.
--passphrase-file <FILE> Read passphrase from the specified file instead of taking it through prompt. Mutually exclusive with -p/--passphrase option. For standard input, use a hyphen (`-'). For an actual file named a hyphen, prepend `./', i.e., `./-'. Note that the trailing CR/LF is trimmed.
-P, --public-key Export a public key instead of private key.
-b, --bytes Print raw bytes instead of hexadecimal. No trailing LF appended.
--json Export a Web3 Secret Storage Formatted json
--path <String> Path to key store to export from.
-h, --help Show help message
Letโs retrieve the private key using the --passphrase
option with the passphrase you previously entered.
๐จ
For demonstration purposes, we will expose the private key here, but never expose your private key in any other context.
planet key export 1fd94a3e-2273-489b-bd44-b62036e2c07d --passphrase=***************
The output will be:
9fe5f7c309495d284ca36b948fdeca0e65b21a019e2f8a03efd849df88fab102
Now, letโs export the public key using the --public-key
option.
planet key export 1fd94a3e-2273-489b-bd44-b62036e2c07d --passphrase=*************** --public-key
The output will be:
033dafc7bf6d603578a8c51b04430b738aeeead8a012e1dcbd8c75cf18a625cf14
Hereโs a summary of the key information weโve generated:
Key ID: 1fd94a3e-2273-489b-bd44-b62036e2c07d
Private Key: 9fe5f7c309495d284ca36b948fdeca0e65b21a019e2f8a03efd849df88fab102
Public Key: 033dafc7bf6d603578a8c51b04430b738aeeead8a012e1dcbd8c75cf18a625cf14
Address: 0xb4179Ad0d7565A6EcFA70d2a0f727461039e0159
๐
Great work! Youโve just learned how to create and manage a private key using the planet
CLI. Next, weโll use this key to create a genesis block.