Skip to content
ItFlyingStart edited this page Jul 7, 2020 · 2 revisions

Elina is an investor and she would like to earn the passive income by staking her ADA. This is what she needs to do: Elina's action list

1. Create stake & payment account

Create the next directories in the working directory:

mkdir addresses
mkdir transactions

And follow the next steps to create a new stake & payment account:

New stake payment account

Step 1: create new payment key

cardano-cli shelley address key-gen \
    --verification-key-file addresses/payment1.vkey \
    --signing-key-file addresses/payment1.skey

Step 2: create new stake key

cardano-cli shelley stake-address key-gen \
    --verification-key-file addresses/stake1.vkey \
    --signing-key-file addresses/stake1.skey

Step 3: create payment address with payment key and stake key

The payment address can be used to transfer funds.

cardano-cli shelley address build \
    --payment-verification-key-file addresses/payment1.vkey \
    --stake-verification-key-file addresses/stake1.vkey \
    --out-file addresses/payment1.addr \
    --testnet-magic 42

Step 4: create stake address with stake key

The stake address will be used to collect the delegation rewards.

cardano-cli shelley stake-address build \
    --staking-verification-key-file addresses/stake1.vkey \
    --out-file addresses/stake1.addr \
    --testnet-magic 42

Step 5: check funds in the payment address Set environment variable CARDANO_NODE_SOCKET_PATH to the socket-path specified in the node configuration. For example:

export CARDANO_NODE_SOCKET_PATH=relay/db/node.socket

Check funds with the next command

cardano-cli shelley query utxo \
    --address $(cat addresses/payment1.addr) \
    --testnet-magic 42

Example result:

                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5     0       20000000000

2. Register stake certificate

Register stake certificate

Step 1: get the protocol parameters

Get the protocol parameters if not done yet.

cardano-cli shelley query protocol-parameters \
    --testnet-magic 42 \
    --out-file configuration/protocol.json

Step 2: create a stake certificate

cardano-cli shelley stake-address registration-certificate \
    --staking-verification-key-file addresses/stake1.vkey \
    --out-file addresses/stake1.cert

Step 3: retrieve the UTXO details from the payment address

export CARDANO_NODE_SOCKET_PATH=relay/db/node.socket

Retrieve the UTXO details from the payment1.addr address of block-one.

cardano-cli shelley query utxo \
    --address $(cat addresses/payment1.addr) \
    --testnet-magic 42

Example result:

                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5     0       20000000000

Step 4: determine the appropiate TTL (Time to live)

cardano-cli shelley query tip \
    --testnet-magic 42

Example result:

Tip (SlotNo {unSlotNo = 498783}) (ShelleyHash {unShelleyHash = HashHeader {unHashHeader = 59a62c46e57390bf20105265b23a06306b4339dca89bbc4092c98e42e5501e1d}}) (BlockNo {unBlockNo = 23334})

Extract the current slot number unSlotNo, which is 498783 in this example. And increase it with 2000. --ttl is:

498783 + 2000 = 500783

Step 5: calculate the fee

cardano-cli shelley transaction calculate-min-fee \
    --tx-in-count 1 \
    --tx-out-count 1 \
    --ttl 500783 \
    --testnet-magic 42 \
    --signing-key-file addresses/payment1.skey \
    --signing-key-file addresses/stake1.skey \
    --certificate addresses/stake1.cert \
    --protocol-params-file configuration/protocol.json

Example result:

runTxCalculateMinFee: 171133

Which means that we need to pay a transaction fee --fee of 171133 Lovelace.

Retrieve the registration fee for our stake certificate:

cat configuration/genesis.json | grep keyDeposit
"keyDeposit": 400000,

Step 6: select UTXO and calculate the remainder funds

Select the UTXO 26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5 to pay the transaction fee:

                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5     0       20000000000
...

--tx-in is:

--tx-in 26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5#0

--tx-out is the remainder funds, which need to be sent back to the sender payment address. Therefore we need to calculate the change first: current total funds - registration fee - transfer fee.

20000000000 - 400000 - 171133 = 19999428867

Thus --tx-out can be constructed like this:

--tx-out $(cat addresses/payment1.addr)+19999428867

Step 7: build the transaction Now we have all required input parameters to build the transaction.

cardano-cli shelley transaction build-raw \
    --tx-in 26299fbf091dda12993a7f208bcb44a5a185077fc10ade11e2d9f017abfd98d5#0 \
    --tx-out $(cat addresses/payment1.addr)+19999428867 \
    --ttl 500783 \
    --fee 171133 \
    --out-file transactions/tx1.txbody \
    --certificate addresses/stake1.cert

tx1.txbody contains the output raw file.

Step 8: sign the transaction We use the sender key pay.skey and stake.skey to sign the transaction file tx1.txbody.

cardano-cli shelley transaction sign \
    --tx-body-file transactions/tx1.txbody \
    --signing-key-file addresses/payment1.skey \
    --signing-key-file addresses/stake1.skey \
    --testnet-magic 42 \
    --tx-file transactions/tx1.signed

tx1.signed contains the signed transaction file.

Step 9: submit the transaction We submit the signed transaction file tx1.signed.

cardano-cli shelley transaction submit \
    --tx-file transactions/tx1.signed \
    --testnet-magic 42

3. Register delegation certificate

Register delegation certificate

Step 1: get the protocol parameters

This is an optional step. Get the protocol parameters if not done yet.

cardano-cli shelley query protocol-parameters \
    --testnet-magic 42 \
    --out-file configuration/protocol.json

Step 2: find a stake pool to delegate

Elina would like to delegate her stake to the stake pools of Frank. She makes use of PoolTool (https://ff.pooltool.io/) to find the verification/public key of his pool:

Find stake pool

Create a new file filename.vkey. For example: pool1.vkey

mkdir pool

nano pool/frank-pool1.vkey

Make use of the next file template and replace the pool vkey:

type: Node operator verification key
title: Stake Pool Operator Verification Key
cbor-hex:
 5820efd937b134864272fe285b6989021fb837f3c217419e01e63e832eb66f4432e8

Stake pool vkey

Step 3: create the delegation certificate

Specify the pool vkey-file in --stake-pool-verification-key-file, which is pool1.vkey in this example.

cardano-cli shelley stake-address delegation-certificate \
    --staking-verification-key-file addresses/stake1.vkey \
    --stake-pool-verification-key-file pool/frank-pool1.vkey \
    --out-file pool/delegation.cert

Step 4: retrieve the UTXO details from the payment address of the sender

cardano-cli shelley query utxo \
    --address $(cat addresses/payment1.addr) \
    --testnet-magic 42

Example result:

                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
21bcd80a9e9908686b7b2de92ea45899c53ae36a79b984fb7d5ec1078820e93a     0       19999428867

Step 5: determine the appropiate TTL (Time to live)

export CARDANO_NODE_SOCKET_PATH=relay/db/node.socket
cardano-cli shelley query tip \
    --testnet-magic 42

Example result:

Tip (SlotNo {unSlotNo = 573200}) (ShelleyHash {unShelleyHash = HashHeader {unHashHeader = bcbbeca5ab2851d11367f69c4e78f8936b0f13ef0546e731ac120efda72ea574}}) (BlockNo {unBlockNo = 27073})

Extract the current slot number unSlotNo, which is 573200 in this example. And increase it with 2000. --ttl is:

573200 + 2000 = 575200

Step 6: calculate the fee

cardano-cli shelley transaction calculate-min-fee \
    --tx-in-count 1 \
    --tx-out-count 1 \
    --ttl 575200 \
    --testnet-magic 42 \
    --signing-key-file addresses/payment1.skey \
    --signing-key-file addresses/stake1.skey \
    --certificate pool/delegation.cert \
    --protocol-params-file configuration/protocol.json

Example result:

runTxCalculateMinFee: 172453

Which means that we need to pay a transaction fee --fee of 172453 Lovelace.

Step 6: select UTXO and calculate the remainder funds

We will use the UTXO 21bcd80a9e9908686b7b2de92ea45899c53ae36a79b984fb7d5ec1078820e93a to pay the transaction fee:

                           TxHash                                 TxIx        Lovelace
----------------------------------------------------------------------------------------
21bcd80a9e9908686b7b2de92ea45899c53ae36a79b984fb7d5ec1078820e93a     0       19999428867
...

--tx-in is:

--tx-in 21bcd80a9e9908686b7b2de92ea45899c53ae36a79b984fb7d5ec1078820e93a#0

--tx-out is the remainder funds, which need to be sent back to the sender payment address. Therefore we need to calculate the change first: current total funds - transfer fee.

19999428867 - 172453 = 19999256414

Thus --tx-out can be constructed like this:

--tx-out $(cat addresses/payment1.addr)+19999256414

Step 7: build the transaction Now we have all required input parameters to build the transaction.

cardano-cli shelley transaction build-raw \
    --tx-in 21bcd80a9e9908686b7b2de92ea45899c53ae36a79b984fb7d5ec1078820e93a#0 \
    --tx-out $(cat addresses/payment1.addr)+19999256414 \
    --ttl 575200 \
    --fee 172453 \
    --out-file transactions/tx1.txbody \
    --certificate pool/delegation.cert

tx1.txbody contains the output raw file.

Step 8: sign the transaction We use the sender key pay.skey and stake.skey to sign the transaction file tx1.txbody.

cardano-cli shelley transaction sign \
    --tx-body-file transactions/tx1.txbody \
    --signing-key-file addresses/payment1.skey \
    --signing-key-file addresses/stake1.skey \
    --testnet-magic 42 \
    --tx-file transactions/tx1.signed

tx1.signed contains the signed transaction file.

Step 9: submit the transaction We submit the signed transaction file tx1.signed.

cardano-cli shelley transaction submit \
    --tx-file transactions/tx1.signed \
    --testnet-magic 42
Clone this wiki locally