My binance address is DdzFFzCqrhsq3cqj7d9rs6f1GECZR3oUeNwvnSigeKMS81Ec4pcRxihWwVCco9CWvFrw4pMB8yvRKRzfoJsXcqofzz3L6wNK9FQAQpii
(a small question why it does not have the prefix addr
like any Yoroi wallet?)
Steps:
1- Get the slot and account balance
# my producer node
currentSlot=$(cardano-cli query tip --mainnet | jq -r '.slot')
echo Current Slot: $currentSlot
cardano-cli query utxo \
--address $(cat payment.addr) \
--mainnet > fullUtxo.out
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
The ouput is
# my producer node
cat balance.out
9f904d7a128bdfc1057b74a92918c410952ea301fcc89c3b5412b26c609193e5 0 695847765 lovelace
2- Then get the transaction hash, transaction index, …:
# my producer node
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}
The output is:
# my producer node
Total ADA balance: 695847765
Number of UTXOs: 1
3- Calculate the fee
# my producer node
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $my_binance_addr+695847765 \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee 0 \
--out-file tx.tmp
fee=$(cardano-cli transaction calculate-min-fee \
--tx-body-file tx.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 1 \
--mainnet \
--witness-count 2 \
--byron-witness-count 0 \
--protocol-params-file params.json | awk '{ print $1 }')
echo fee: $fee
Output:
# my producer node
fee: 178129
4- Check the transaction output
# my producer node
txOut=$((${total_balance}-${stakeAddressDeposit}-${fee}))
echo Change Output: ${txOut}
Output:
Change Output: 696025894
5- Build the transaction
# my producer node
cardano-cli transaction build-raw \
${tx_in} \
--tx-out $my_binance_addr+${txOut} \
--invalid-hereafter $(( ${currentSlot} + 10000)) \
--fee ${fee} \
--out-file tx.raw
6- And then I copy tx.raw
to my cold machine to sign it:
# my cold machine
cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file payment.skey \
--mainnet \
--out-file tx.signed
7- Submit transaction
And then I copy tx.signed
to my producer node and submit the transaction
# my producer node
cardano-cli transaction submit \
--tx-file tx.signed \
--mainnet
Output:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError
ShelleyBasedEraMary (ApplyTxError [UtxowFailure
(UtxoFailure (ValueNotConservedUTxO
(Value 695847765 (fromList [])) (Value 696204023 (fromList []))))])
Please help!