Skip to content

Instantly share code, notes, and snippets.

@Willburn
Created May 16, 2020 01:12
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 Willburn/5240f6f2fc45e49a1bc01af183ae5dfd to your computer and use it in GitHub Desktop.
Save Willburn/5240f6f2fc45e49a1bc01af183ae5dfd to your computer and use it in GitHub Desktop.
multiple (2) transaction script
cat << "EOF"
``.'",,:>*r!~'`
`',,,,,,,:::::^/^!!~`
`.'"",,'',:~!^::!:=;;>ii!'
`.',''.`````:....';,,~::=vvl^`
.',,'....'',::,,::::::::>;ri|\\:`
`.,,,''` ',.```````,.'',,~^^:!^>iJ?`
`'''.````',. `.':,,,"~:!ii7l7v7Jr`
',,,':::~,.....!::,,,,',,!":::::|7!:;>`
',,,'.:'.`` :,.```.',:v;!:!^r?xv|il;
`,":,,,,''',',,":::,::*\**^^!!:!*>!:!::rl`
,:::"~,,,,,,::.`````..,r,,,,"~~:!\!;r?/l{:
`,,,:,,::;::!^^*\~.,:"~~:::::::!:::!!il7\:>\
` '` ,"",:!:,:!r:~:;,:c:';,,,,,"~~~~!!::::|llz^>s.
a! .@L `~::!>?zi:~!^::;!!^t::~~::::::::!*;rr?ll/7cvz'
"@K .@L '"~:;r\u6{,:|;::!!!l|"""""::~~~::::::!7/:;)lC'
UB@, '6Rd@/ ~OHg^ :::!^*{wdgr;L>~:!^^^zr^rr;;?r>>rrr>>>?z7|/7sv`
.@rUe OD`.@L `:d# ~":!^>ue$Bu">*:!!!!!v::)!::::!^>?)L!:!^>|iv}?
}Q:c@, Qu .@L /By8Q `'!>^>?|/yw6WE\7l*|\//cxr=7|?\LlzsJzzc|Ll7vvlvz/r!,`
,@wFFQA wB,"@L RH.eQ ``.'''..',,,,,:!!;!:"""":!rrr^rr^!~:!^rrr^:'``
rk` >X.`vp6u! ,ad4C `.```````.'.......``````````
:!' `::``,:^^!' '^!!:~.`:!!!:!.:!. `!; `~^rr!' `:!>*;, `,:r=^:`,!,
^lL:`//`!\^,://,,l=,!||`,"*\:,`ri,`,i\ .?L,,\L'^\;'"\/,:\^',\i~:l~
rc>L*)i.cl' `rl:~l|:r|! /L. >/|^/)l .ci;!l\'ll'``>l:>)"``^l::l!
rl,'|l)`=l?^rL/.~|="||. LL. >i,`'il .)L",'` ^|=r>L*`~c\*>L)':l>"~:
~!. `!!``,:!!:` ';" ,!" ;^` :!. `!! `:: ':::,` ':::~` ':::::
__ _____ ____ ______________ __ ______
/ |/ / / / / / /_ __/ _/ __ \/ / / ____/
/ /|_/ / / / / / / / / // /_/ / / / __/
/ / / / /_/ / /___/ / _/ // ____/ /___/ /___
/_/__///////_////__/_/ /_/////__ ///___///////__ ______________ _ __
/_ __/ __ \/ | / | / / ___// | / ____/ |/_ __/ _/ __ \/ | / /
/ / / /_/ / /| | / |/ /\__ \/ /| |/ / / /| | / / / // / / / |/ /
/ / / _, _/ ___ |/ /| /___/ / ___ / /___/ ___ |/ / _/ // /_/ / /| /
/_/_///_|////__///// /////////_/__///____/_/ |_/_/ /___/\____/_/ |_/
/ ___// ____/ __ \/ _/ __ \/_ __/
\__ \/ / / /_/ // // /_/ / / /
___/ / /___/ _, _// // ____/ / /
/____/\____/_/ |_/___/_/ /_/
EOF
# ASCII ART http://patorjk.com/software/taag/#p=display&f=Slant&t=MULTIPLE%0ATRANSACATION%0ASCRIPT
# ASCII IMAGE https://cloudapps.herokuapp.com/imagetoascii/
addr_dir=$CNODEDIRADDR
if [ -z "$CNODEDIRADDR" ]; then
echo CNODEDIRADDR env variable set to $CNODEDIRADDR
echo what is your address/skey/vkey default directory
read addr_dir
fi
networkmagic=$CNODENETWORKMAGIC
if [ -z "$CNODENETWORKMAGIC" ]; then
echo CNODENETWORKMAGIC env variable was set to $CNODENETWORKMAGIC
echo what is your network magic number?
read networkmagic
fi
echo how many addresses are you sending to curently only supported 2
read tx_out_count
if [[ "$tx_out_count" == "2" ]]; then
tx_out_transactions=3
fi
echo
echo lets calculate the necassary fees, first lets find protocol parameters
echo and put them to the protocol.json
cardano-cli shelley query protocol-parameters \
--testnet-magic $networkmagic > protocol.json
echo here is the values
cardano-cli shelley query protocol-parameters \
--testnet-magic $networkmagic
echo how many slots do you want the transaction to have time to live before going invalid?
cardano-cli get-tip --socket-path $CARDANO_NODE_SOCKET_PATH --config $CNODECONFIG > gettipfile
currentslot=$(awk 'NR==5 {print $2}' gettipfile)
echo keep in mind the current slot is $currentslot and the slot number should be higher than this
read ttl
echo
echo now lets calcualte the minimum fees for one input, two outputs the ada and the change back
echo
echo name of input addr .skey
echo $(find /opt/cardano/cnode/createaddress/addr/*.skey)
read input_addr_skey
cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count $tx_out_transactions \
--ttl $ttl \
--testnet-magic $networkmagic \
--signing-key-file $addr_dir$input_addr_skey \
--protocol-params-file protocol.json > minfeefile
min_fee=$(awk 'NR==1 {print $2}' minfeefile)
min_fee_ada=$(awk 'NR==1 {print $2/1000000}' minfeefile)
echo minimum fee $min_fee lovelace or $min_fee_ada ADA
echo what address will you use for sending ADA?
echo $(find /opt/cardano/cnode/createaddress/addr/*.addr)
read send_addr
send_actual_addr=$(cat $addr_dir$send_addr)
echo lets get the TxHash of address
cardano-cli shelley query filtered-utxo \
--address $(cat $addr_dir$send_addr) \
--testnet-magic 42 > txhashfile
txhash=$(awk 'NR==3 {print $1}' txhashfile)
txix=$(awk 'NR==3 {print $2}' txhashfile)
addr_lovelace=$(awk 'NR==3 {print $3}' txhashfile)
addr_ada=$(awk 'NR==3 {print $3/1000000}' txhashfile)
echo you will use $txhash TxHash and TxIx $txix
echo account has $addr_lovelace number of lovelace or $addr_ada ADA
if [[ "$tx_out_count" == "2" ]]; then
echo what is the address value of the recieving address1
read recieving_addr1
echo what is the address value of the recieving address2
read recieving_addr2
fi
if [[ "$tx_out_count" == "2" ]]; then
echo how much ada do you want to send to $recieving_addr1, warning NOT in lovelace
read ada_to_send1
let "lovelace_to_send1=ada_to_send1 * 1000000"
echo ok you are sending $lovelace_to_send1 lovelace or $ada_to_send1 ADA to $recieving_addr1
echo how much ada do you want to send to $recieving_addr2, warning NOT in lovelace
read ada_to_send2
let "lovelace_to_send2=ada_to_send2 * 1000000"
echo ok you are sending $lovelace_to_send1 lovelace or $ada_to_send1 ADA to $recieving_addr1
let "lovelace_left=$addr_lovelace - $min_fee - $lovelace_to_send1 - $lovelace_to_send2"
let "ada_left=lovelace_left / 1000000"
echo the lovelace that will be left in the account is $lovelace_left or $ada_left ADA
echo this is after sending $lovelace_to_send1 and $lovelace_to_send2 lovelace or $ada_to_send1 and $ada_to_send2 ADA
echo you are sending $lovelace_to_send1 to address $recieving_addr1 and $lovelace_to_send2 lovelace to $recieving_addr2 from $send_actual_addr please confirm by hitting enter or abort with ctrl c
read hitenter
sleep 1
echo we are building the transaction now
cardano-cli shelley transaction build-raw \
--tx-in $txhash#$txix \
--tx-out $recieving_addr1+$lovelace_to_send1 \
--tx-out $recieving_addr2+$lovelace_to_send2 \
--tx-out $send_actual_addr+$lovelace_left \
--ttl $ttl \
--fee $min_fee \
--tx-body-file tx001.raw
sleep 1
echo we are now signing the transaction
cardano-cli shelley transaction sign \
--tx-body-file tx001.raw \
--signing-key-file $addr_dir$input_addr_skey \
--testnet-magic $networkmagic \
--tx-file tx001.signed
sleep 1
echo we are now submitting the transaction
cardano-cli shelley transaction submit \
--tx-filepath tx001.signed \
--testnet-magic $networkmagic
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment