Generate keys and addresses

We need to create two sets of keys and addresses. One set to control our funds (make and receive payments) and one set to control our stake (to participate in the protocol delegating our stake)
Let's produce our cryptographic keys first, as we will need them to later create our addresses:
WARNING
For ease of use, and for this course only, we will keep our Cardano Preview Testnet key files in the server. But this is NOT SECURE.
In a real life scenario (MAINNET), you need to have your keys under cold storage.

Payment key pair

Generate a payment key pair:
cardano-cli address key-gen \
--verification-key-file payment.vkey \
--signing-key-file payment.skey
This will create two files (here named payment.vkey and payment.skey), one containing the public verification key, one the private signing key.
The files are in plain-text format and human readable:
cat payment.vkey
{
"type": "PaymentVerificationKeyShelley_ed25519",
"description": "Payment Verification Key",
"cborHex": "5820d84d47b1eecc9efc6008a65a7e179a8da8d7d5fe050b6ca3bfffe360d19f88a7"
}
The first line describes the file type and should not be changed. The second line is a free form text that we could change if we so wished. The key itself is the cbor-encoded byte-string in the fourth line.

Stake key pair

Now let us create our stake key pair :
cardano-cli stake-address key-gen \
--verification-key-file stake.vkey \
--signing-key-file stake.skey
As before, we can read the files:
cat stake.vkey
{
"type": "StakeVerificationKeyShelley_ed25519",
"description": "Stake Verification Key",
"cborHex": "58200984fedb38f51ca6d8b0c67f5ba53347c90ae3cc7963b64f8c549b60b233e6d9"
}

Payment address

We then use payment.vkey and stake.vkey to build our payment address:
cardano-cli address build \
--payment-verification-key-file payment.vkey \
--stake-verification-key-file stake.vkey \
--out-file payment.addr \
--testnet-magic 2
This creates saves the addres to the file payment.addr. Note that this address is already associated with our stake keys:
cat payment.addr
addr_test1qqmz6kgthyv4c4pgu3k2egpfuzu5pyrcav6kjz95lxgt7g75jsksfxu29p622vqx2jhxvxg6jjtgqla3wwvyhjwlsjvstads72

Stake address

Now we can build our stake address and save it to stake.addr This is a very special type of address, this is where our rewards from delegating to a pool go to. Note that we cannot send funds to this type of address directly.
cardano-cli stake-address build \
--stake-verification-key-file stake.vkey \
--testnet-magic 2 \
--out-file stake.addr
cat stake.addr
​
> stake_test1ur2fgtgynw9zsa99xqr9ftnxrydff95q07ch8xzte80cfxgf3jye0To query your address (see the utxo's at that address), you first need to set environment variable CARDANO_NODE_SOCKET_PATH to the socket-path specified in your node configuration. In this example we will use the relay node created in the previous steps:
​
Query your payment address balance with:
cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 2
TxHash TxIx Amount
--------------------------------------------------------------------------------------
As expected, our address does not contain any funds, lets fix that using the faucet
QUESTIONS AND FEEDBACK
If you have any questions and suggestions while taking the lessons please feel free to ask in the forum and we will respond as soon as possible.