-
Notifications
You must be signed in to change notification settings - Fork 4
/
send_ada.sh
101 lines (85 loc) · 2.54 KB
/
send_ada.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -e
###############################################################################
###############################################################################
NAME="minter"
SENDER_ADDR=$(cat ${NAME}/${NAME}_base.addr)
RECEIVER_ADDR=$(cat receiver.addr)
###############################################################################
###############################################################################
### Check if a directory does not exist ###
if [ -d transaction ]
then
echo "Folder Exists."
else
mkdir -p transaction
fi
cd transaction
# Passive relay or Daedalus is required.
#
# Must have a live Network.Socket.connect
# protocol
echo "Getting protocol parameters"
cardano-cli query protocol-parameters \
--mainnet \
--out-file protocol.json
# get utxo
echo "Getting utxo"
cardano-cli query utxo \
--cardano-mode \
--mainnet \
--address ${SENDER_ADDR} \
--out-file utxo.json
# transaction variables
TXNS=$(jq length utxo.json)
alltxin=""
TXIN=$(jq -r --arg alltxin "" 'keys[] | . + $alltxin + " --tx-in"' utxo.json)
HEXTXIN=${TXIN::-8}
ADA_BALANCE=$(jq .[].value.lovelace utxo.json | awk '{sum=sum+$0} END{print sum}' )
echo "ADA" ${ADA_BALANCE}
# Next tip before no transaction
echo "Getting chain tip"
cardano-cli query tip --mainnet --out-file tip.json
TIP=$(jq .slot tip.json)
DELTA=200000
FINALTIP=$(( ${DELTA} + ${TIP} ))
echo "Building Draft Transaction"
cardano-cli transaction build-raw \
--mary-era \
--fee 0 \
--tx-in $HEXTXIN \
--tx-out ${RECEIVER_ADDR}+${ADA_BALANCE} \
--invalid-hereafter $FINALTIP \
--out-file tx.draft
echo "Calculating Transaction Fee"
FEE=$(cardano-cli transaction calculate-min-fee \
--tx-body-file tx.draft \
--tx-in-count ${TXNS} \
--tx-out-count 2 \
--witness-count 3 \
--mainnet \
--protocol-params-file protocol.json \
| tr -dc '0-9')
echo $SENDER "has" $BALANCE "ADA"
echo "The fee is" ${FEE} "to move" ${ADA_BALANCE} "Lovelace"
CHANGE=$(( ${ADA_BALANCE} - ${FEE} ))
echo "The change is" ${CHANGE}
echo "Building Raw Transaction"
cardano-cli transaction build-raw \
--mary-era \
--fee $FEE \
--tx-in $HEXTXIN \
--tx-out ${RECEIVER_ADDR}+${CHANGE} \
--invalid-hereafter $FINALTIP \
--out-file tx.raw
echo "Signing Transaction"
cardano-cli transaction sign \
--tx-body-file tx.raw \
--signing-key-file "../minter/minter_payment.skey" \
--mainnet \
--out-file tx.signed
# ###### THIS MAKES IT LIVE #####################################################
# cardano-cli transaction submit \
# --tx-file tx.signed \
# --mainnet
# ##############################################################################