Skip to content

Instantly share code, notes, and snippets.

@os11k
Last active May 17, 2023 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os11k/75cfb9d2b883a99f19a66955c6be602e to your computer and use it in GitHub Desktop.
Save os11k/75cfb9d2b883a99f19a66955c6be602e to your computer and use it in GitHub Desktop.
#######!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#######
# PLEASE MAKE SURE DURING BUILD TRANSACTION STEP YOU PUT YOUR OWN POOL ID after required-signer-hash!!!!!!!!!!!!!!!!
# PLEASE MAKE SURE DURING BUILD TRANSACTION STEP YOU PUT YOUR OWN POOL ID after required-signer-hash!!!!!!!!!!!!!!!!
# PLEASE MAKE SURE DURING BUILD TRANSACTION STEP YOU PUT YOUR OWN POOL ID after required-signer-hash!!!!!!!!!!!!!!!!
#######!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#######
# first make sure we have json with our voting, like this:
# ls -alt /tmp/CIP-0094_d8c1b1d871a27d74fbddfa16d28ce38288411a75c5d3561bb74066bcd54689e2-poll-answer.json
# it should contain something like this:
# cat /tmp/CIP-0094_d8c1b1d871a27d74fbddfa16d28ce38288411a75c5d3561bb74066bcd54689e2-poll-answer.json
#{
# "94": {
# "map": [
# {
# "k": {
# "int": 2
# },
# "v": {
# "bytes": "62c6be72bdf0b5b16e37e4f55cf87e46bd1281ee358b25b8006358bf25e71798"
# }
# },
# {
# "k": {
# "int": 3
# },
# "v": {
# "int": 2
# }
# }
# ]
# }
#}
# If we have this file in place and it contains proper info, then we can move on.
# First lets find out a tip
currentSlot=$(cardano-cli query tip --testnet-magic 1 | jq -r '.slot')
echo Current Slot: $currentSlot
#Find your balance and UTXOs.
cardano-cli query utxo \
--address $(cat payment.addr) \
--testnet-magic 1 > fullUtxo.out
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
cat balance.out
tx_in=""
total_balance=0
while read -r utxo; do
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
idx=$(awk '{ print $2 }' <<< "${utxo}")
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
total_balance=$((${total_balance}+${utxo_balance}))
echo TxHash: ${in_addr}#${idx}
echo ADA: ${utxo_balance}
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
done < balance.out
txcnt=$(cat balance.out | wc -l)
echo Total ADA balance: ${total_balance}
echo Number of UTXOs: ${txcnt}
# PLEASE MAKE SURE DURING BUILD TRANSACTION STEP YOU PUT YOUR OWN POOL ID after required-signer-hash!!!!!!!!!!!!!!!!
#build raw transaction:
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat ./payment.addr)+${total_balance} \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee 0 \
--json-metadata-detailed-schema \
--required-signer-hash 54977486bc076ef24dab6f34652c1d33113f871ebc5e863b2488e03c \
--metadata-json-file /tmp/CIP-0094_d8c1b1d871a27d74fbddfa16d28ce38288411a75c5d3561bb74066bcd54689e2-poll-answer.json \
--out-file tx.tmp
#calculate min-fee:
fee=$(cardano-cli transaction calculate-min-fee \
--tx-body-file tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 1 \
--testnet-magic 1 \
--witness-count 2 \
--byron-witness-count 0 \
--protocol-params-file params.json | awk '{ print $1 }')
echo fee: $fee
#Calculate your change output.
txOut=$((${total_balance}-${fee}))
echo txOut: ${txOut}
# PLEASE MAKE SURE DURING BUILD TRANSACTION STEP YOU PUT YOUR OWN POOL ID after required-signer-hash!!!!!!!!!!!!!!!!
#build transaction
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $(cat ./payment.addr)+${txOut} \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee ${fee} \
--json-metadata-detailed-schema \
--required-signer-hash 54977486bc076ef24dab6f34652c1d33113f871ebc5e863b2488e03c \
--metadata-json-file /tmp/CIP-0094_d8c1b1d871a27d74fbddfa16d28ce38288411a75c5d3561bb74066bcd54689e2-poll-answer.json \
--out-file tx.raw
#sign the transaction
cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--signing-key-file $HOME/cold-keys/node.skey \
--testnet-magic 1 \
--out-file tx.signed
#send the transaction
cardano-cli transaction submit \
--tx-file tx.signed \
--testnet-magic 1
@os11k
Copy link
Author

os11k commented May 6, 2023

Seems we don't need to sign with stake.skey, but I will leave it here, because it is how I tested and it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment