-
Notifications
You must be signed in to change notification settings - Fork 2
Dennis
Dennis has heard al lot of good things about Cardano and to learn more about Cardano project. His friend Bob has sent some ADA to him, which he will use to delegate his stake to the stake pool operated by Cindy.
Create the next directories in the working directory:
mkdir addresses
mkdir transactions
mkdir configuration
And follow the next steps to create a 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
----------------------------------------------------------------------------------------
dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869 0 500000000
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
----------------------------------------------------------------------------------------
dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869 0 500000000
Step 4: determine the appropiate TTL
(Time to live)
cardano-cli shelley query tip \
--testnet-magic 42
Example result:
Tip (SlotNo {unSlotNo = 578200}) (ShelleyHash {unShelleyHash = HashHeader {unHashHeader = 5606122727170b4afc38bdf67b64a897cd9b1fbf5599fbb035dbb0d9425f127d}}) (BlockNo {unBlockNo = 27323})
Extract the current slot number unSlotNo
, which is 578200
in this example. And increase it with 2000.
--ttl
is:
578200 + 2000 = 580200
Step 5: calculate the fee
cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count 1 \
--ttl 580200 \
--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 dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869
to pay the transaction fee:
TxHash TxIx Lovelace
----------------------------------------------------------------------------------------
dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869 0 500000000
...
--tx-in
is:
--tx-in dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869#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
.
500000000 - 400000 - 171133 = 499428867
Thus --tx-out
can be constructed like this:
--tx-out $(cat addresses/payment1.addr)+499428867
Step 7: build the transaction Now we have all required input parameters to build the transaction.
cardano-cli shelley transaction build-raw \
--tx-in dde6e27f62dbf8fc5512ed82fc33be147522e24b7091ef8e9ba1ab18d9cba869#0 \
--tx-out $(cat addresses/payment1.addr)+499428867 \
--ttl 580200 \
--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
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
Dennis would like to delegate his stake to the stake pools of Cindy. He makes use of PoolTool (https://ff.pooltool.io/) to find the verification/public key of his pool:
Create a new file filename.vkey
. For example: pool1.vkey
mkdir pool
nano pool/cindy-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:
58200d81e2bd8435a8a2a48a47566236a33c5ccf6279ce6eaa227083be66b6b84d10
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/cindy-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
----------------------------------------------------------------------------------------
fe165c31e709026a7c1dcf4de7ed088cc9525a8d1a2547cd779e4eefa0d901e2 0 499428867
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 = 582571}) (ShelleyHash {unShelleyHash = HashHeader {unHashHeader = 68356bbf0a899971a8ec26b4890bfa10c30e02b455a222ab04bff050c8e988b6}}) (BlockNo {unBlockNo = 27539})
Extract the current slot number unSlotNo
, which is 582571
in this example. And increase it with 2000.
--ttl
is:
582571 + 2000 = 584571
Step 6: calculate the fee
cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count 1 \
--ttl 584571 \
--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 fe165c31e709026a7c1dcf4de7ed088cc9525a8d1a2547cd779e4eefa0d901e2
to pay the transaction fee:
TxHash TxIx Lovelace
----------------------------------------------------------------------------------------
fe165c31e709026a7c1dcf4de7ed088cc9525a8d1a2547cd779e4eefa0d901e2 0 499428867
...
--tx-in
is:
--tx-in fe165c31e709026a7c1dcf4de7ed088cc9525a8d1a2547cd779e4eefa0d901e2#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
.
499428867 - 172453 = 499256414
Thus --tx-out
can be constructed like this:
--tx-out $(cat addresses/payment1.addr)+499256414
Step 7: build the transaction Now we have all required input parameters to build the transaction.
cardano-cli shelley transaction build-raw \
--tx-in fe165c31e709026a7c1dcf4de7ed088cc9525a8d1a2547cd779e4eefa0d901e2#0 \
--tx-out $(cat addresses/payment1.addr)+499256414 \
--ttl 584571 \
--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