Skip to content

Instantly share code, notes, and snippets.

@Willburn
Created May 24, 2020 00:11
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/befaf9805d6167939894edd8bdada8a8 to your computer and use it in GitHub Desktop.
Save Willburn/befaf9805d6167939894edd8bdada8a8 to your computer and use it in GitHub Desktop.
simple 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=TRANSACATION%0ASCRIPT
# ASCII IMAGE https://cloudapps.herokuapp.com/imagetoascii/
source ~/.profile
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 lets calculate the necassary fees, first lets find protocol parameters
echo and put them in the protocol.json
cardano-cli shelley query protocol-parameters \
--testnet-magic $networkmagic > protocol.json
echo what signing key will you use for the transaction?
echo $(find $addr_dir*.skey)
echo name of input addr .skey file
read input_addr_skey
echo how many slots do you want the transaction to have time to live before going invalid
cardano-cli get-tip --testnet-magic $networkmagic > 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 now lets calculate the minimum fees for one input, two outputs the ada and the change back
echo
cardano-cli shelley transaction calculate-min-fee \
--tx-in-count 1 \
--tx-out-count 2 \
--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 $addr_dir*.addr)
read send_addr
send_actual_addr=$(cat $addr_dir$send_addr)
echo lets look at the TxHash of address and select one
cardano-cli shelley query utxo \
--address $(cat $addr_dir$send_addr) \
--testnet-magic $networkmagic > txhashfile
awk '{print NR, $1, $2, $3,"\n"}' txhashfile
echo select line number for account you want to use
read txhashnumber
txhash=$(awk 'NR=="'"$txhashnumber"'" {print $1}' txhashfile)
txix=$(awk 'NR=="'"$txhashnumber"'" {print $2}' txhashfile)
addr_lovelace=$(awk 'NR=="'"$txhashnumber"'" {print $3}' txhashfile)
addr_ada=$(awk 'NR=="'"$txhashnumber"'" {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
echo what is the address value of the recieving address
read recieving_addr
echo how much ada do you want to send, warning NOT in lovelace
read ada_to_send
let lovelace_to_send=ada_to_send*1000000
echo ok you are sending $lovelace_to_send lovelace or $ada_to_send ADA
let lovelace_left=addr_lovelace-min_fee-lovelace_to_send
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_send lovelace or $ada_to_send ADA
echo you are sending to address $recieving_addr 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_addr+$lovelace_to_send \
--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-file tx001.signed \
--testnet-magic $networkmagic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment