Categories
cardano Uncategorized

Cardano simple transaction – Testnet

payment2.addr = TO address (addr_test1qqr585tvlc7ylnqvz8pyqwauzrdu0mxag3m7q56grgmgu7sxu2hyfhlkwuxupa9d5085eunq2qywy7hvmvej456flknswgndm3)
payment.addr = FROM address(addr_test1qzvvw5j2636y3r0cg3spu94htzjxupmt2hxld5gxzsp873lpqqmdlvg6k2sfdnzjz8q3pr3q8meydx05q4cacmnzxxesawnv76)

#Draft transaction

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment2.addr)+0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft

#Minimum fee

cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count 2 \
--tx-body-file tx.draft \
--testnet-magic 1097911063 \
--witness-count 3 \
--protocol-params-file protocol.json

minimum fee : 189481

#Calculation

497452809 – 100000000 – 189481 = 397263328
payment.addr – payment2.addr – fee = 397263328

#Get updated slot

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot
updated_currentSlot=$(($currentSlot+1000))
echo Updated Slot: $updated_currentSlot

#Build raw transaction

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment2.addr)+100000000 \
--tx-out $(cat payment.addr)+397263328 \
--ttl 14949695 \
--fee 189481 \
--out-file tx.raw

#Sign transaction

cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

#Submit transaction

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063

root@core:~/cardano-my-node# cat protocol.json | grep minUTxOValue
minUTxOValue“: 1000000,

Shelley command failed: transaction submit Error: Error while submitting tx: ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (OutputTooSmallUTxO [(Addr Mainnet (KeyHashObj (KeyHash “6ccf7afbb2f916c52aa01eeffaa71b500d903ef2421c9b40343a5145”)) (StakeRefBase (KeyHashObj (KeyHash “61ffb9726ac8436bdecfe9b94b9f18d51ce26672452808019212cfdd”))),Coin 472257)])))]

Categories
cardano

Retire cardano stake pool – Testnet

#Current EPOC

cat testnet-shelley-genesis.json | grep epoch
#"epochLength": 432000

cardano-cli shelley query tip --testnet-magic 1097911063 | grep slotNo
#"slotNo": 14711760

expr 14711760 / 432000
#34
#34+1 = earliest epoch for retirement 

cardano-cli shelley query protocol-parameters \
--testnet-magic 1097911063 \
--allegra-era \
--out-file protocol.json

cat protocol.json | grep eMax

#"eMax": 18

#Create deregistration certificate

cardano-cli shelley stake-pool deregistration-certificate \
--cold-verification-key-file node.vkey \
--epoch 35 \
--out-file pool.deregistration

#Draft the transaction

cardano-cli shelley query utxo \
    --address $(cat payment.addr) \
    --testnet-magic 1097911063 \
    --allegra-era

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft \
--certificate-file pool.deregistration

#Calculate the fees

cardano-cli shelley transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 1 \
--witness-count 1 \
--byron-witness-count 0 \
--testnet-magic 1097911063 \
--protocol-params-file protocol.json

#172761

expr 497452809 - 172761 = 497280048

#Build, sign and submit the transaction

#TTL

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot

updated_currentSlot=$(($currentSlot+10000))
echo Updated Slot: $updated_currentSlot
#14721760

cardano-cli shelley transaction build-raw \
--tx-in 173dcc8ce28c8d6c3900363c8c3a18f0dcdc953f1f108d1acf99bbfc66f99d9d#0 \
--tx-out $(cat payment.addr)+497280048 \
--ttl 14721760 \
--fee 172761 \
--out-file tx.raw \
--certificate-file pool.deregistration

#sign
cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file node.skey \
--testnet-magic 1097911063 \
--out-file tx.signed

#submit

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063 

#stackpool status:

cardano-cli stake-pool id --cold-verification-key-file $HOME/cold-keys/node.vkey --output-format hex > stakepoolid.txt
cat stakepoolid.txt

cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era | grep -C 20 $(cat stakepoolid.txt)

Check status

cardano-cli query ledger-state --testnet-magic 1097911063 --allegra-era --out-file ledger-state.json

jq -r '.esLState._delegationState._pstate._pParams."'"$(cat stakepoolid.txt)"'"  // empty' ledger-state.json

Reward status:

cardano-cli query stake-address-info \
    --testnet-magic 1097911063 \
    --allegra-era \
    --address $(cat stake.addr) | jq -r ".[0].rewardAccountBalance"

Refrences:
https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node#19-retire-your-stake-pool

https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/retire_stakepool.html

Categories
cardano

Submit cardano transaction – Testnet

#Get protocol parameters

cardano-cli shelley query protocol-parameters \
--testnet-magic 1097911063 \
--allegra-era \
--out-file protocol.json

#Get the transaction hash and index of the UTXO to spend

cardano-cli shelley query utxo \
  --address $(cat payment.addr) \
  --testnet-magic 1097911063 \
  --allegra-era

Output:

#Draft the transaction

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment.addr)+0 \
--ttl 0 \
--fee 0 \
--out-file tx.draft

TxId = transaction hash
TxIx = transaction index
tx-out = TxOut+Lovelace
TxOut = hex encoded address
Lovelace = Amount of ADA*1000000

#Calculate the fee

cardano-cli shelley transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count 1 \
--tx-out-count 2 \
--witness-count 1 \
--byron-witness-count 0 \
--testnet-magic 1097911063 \
--protocol-params-file protocol.json

Output:
175621

#Calculate the change to send back to payment.addr

expr <UTXO BALANCE> - <AMOUNT TO SEND> - <TRANSACTION FEE>

//Exmaple
expr 497628430 - 497452809 - 175621

#Determine the TTL (time to Live) for the transaction

– TTL = slotNo + N slots
– N = Amount of slots you want to add to give the transaction a window to be included in a block

currentSlot=$(cardano-cli query tip --testnet-magic 1097911063 | jq -r '.slotNo')
echo Current Slot: $currentSlot

updated_currentSlot=$(($currentSlot+1000))
echo Updated Slot: $updated_currentSlot

#Build the transaction

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment.addr)+497452809 \
--ttl 14689800 \
--fee 175621 \
--out-file tx.raw

#Build transaction2

cardano-cli shelley transaction build-raw \
--tx-in 03ed78363f5d715302d84bbc79cfcdd7a7e92eaa1511a8ed87e45b2b07c5713e#0 \
--tx-out $(cat payment2.addr)+100000000 \
--tx-out $(cat payment.addr)+397454217 \
--ttl 14689800 \
--fee 175621 \
--out-file tx.raw

-payment.addr = FROM address
-payment2.addr = TO address

#Sign the transaction

cardano-cli shelley transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file node.skey \
--testnet-magic 1097911063  \
--out-file tx.signed

#Submit the transaction

cardano-cli shelley transaction submit \
--tx-file tx.signed \
--testnet-magic 1097911063

#Check the balances

cardano-cli shelley query utxo \
    --address $(cat payment.addr) \
    --testnet-magic 1097911063 \
    --allegra-era

References :
https://docs.cardano.org/projects/cardano-node/en/1.18.0/reference/transactions.html

https://docs.cardano.org/projects/cardano-node/en/latest/stake-pool-operations/simple_transaction.html

Categories
cardano Uncategorized

Cardano-DevOps

Help cardano community to automate