Created
January 3, 2021 21:15
-
-
Save rcmorano/35327e0d0aaf72baa40b60dce660387c to your computer and use it in GitHub Desktop.
send-tx-thru-dandelion.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
NETWORK_MAGIC=1097911063 | |
SOURCE_ADDRESS=$(cat ~/.cardano/wallets/testnet-repoc/payment.addr) | |
DESTINATION_ADDRESS=addr_test1vq87dp3djy6sz2yj23msw5d6ur96h0jsvks0p8mdwh2c0mghc68m3 | |
PAYMENT_SKEY=${HOME}/.cardano/wallets/testnet-repoc/payment.skey | |
SEND_AMOUNT=10000000 | |
CURRENT_EPOCH=$(curl -s "https://postgrest-api.testnet.dandelion.link/epoch?select=no&limit=1&order=no.desc" | jq .[].no) | |
TTL_VALID_FROM_SLOT_NO=$(curl -s "https://postgrest-api.testnet.dandelion.link/block?select=slot_no&epoch_no=eq.${CURRENT_EPOCH}&limit=1&order=slot_no.desc" | jq .[].slot_no) | |
curl 'https://graphql-api.testnet.dandelion.link/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: https://graphql-api.testnet.dandelion.link' --data-binary '{"query":"query keyNetworkInfo {\n genesis {\n shelley {\n protocolParams {\n a0\n decentralisationParam\n eMax\n extraEntropy\n keyDeposit\n maxBlockBodySize\n maxBlockHeaderSize\n maxTxSize\n minFeeA\n minFeeB\n minPoolCost\n minUTxOValue\n nOpt\n poolDeposit\n protocolVersion\n rho\n tau\n }\n }\n }\n}"}' --compressed | jq .data.genesis.shelley.protocolParams > /tmp/protparams.json | |
cat >/tmp/query<<EOF | |
{ "query" : "query utxoSetForAddress ( | |
\$address: String! | |
){ | |
utxos( | |
order_by: { value: desc } | |
where: { address: { _eq: \$address }} | |
) { | |
address | |
transaction { | |
hash | |
} | |
value | |
} | |
}", | |
"variables": { | |
"address": "${SOURCE_ADDRESS}" | |
} | |
} | |
EOF | |
cat /tmp/query | tr '\r\n' ' ' > /tmp/query.sanitized | |
curl https://graphql-api.testnet.dandelion.link/ \ | |
-H 'Content-Type: application/json' -H 'Accept: application/json' \ | |
--data-binary @/tmp/query.sanitized | jq .data.utxos > /tmp/utxos.json | |
IN_UTXO=$(jq -r 'to_entries | .[] | "\(.value.transaction.hash)#\(.key)"' /tmp/utxos.json | awk '{print "--tx-in "$0}' | xargs) | |
UTXO_COUNT=$(jq length /tmp/utxos.json) | |
IN_BALANCE="$(jq -r .[].value /tmp/utxos.json | awk '{s+=$1} END {printf "%.0f", s}')" | |
cardano-cli transaction build-raw \ | |
--allegra-era \ | |
--fee 0 \ | |
${IN_UTXO} \ | |
--tx-out="${DESTINATION_ADDRESS}+${SEND_AMOUNT} lovelace" \ | |
--tx-out="${SOURCE_ADDRESS}+$(( ${IN_BALANCE} - ${SEND_AMOUNT})) lovelace" \ | |
--out-file txbody | |
ACTUAL_MIN_FEE=$(cardano-cli transaction calculate-min-fee \ | |
--tx-body-file txbody \ | |
--tx-in-count ${UTXO_COUNT} \ | |
--tx-out-count 1 \ | |
--witness-count 1 \ | |
--byron-witness-count 0 \ | |
--protocol-params-file /tmp/protparams.json | awk '{print $1}') | |
cardano-cli transaction build-raw \ | |
--allegra-era \ | |
--invalid-hereafter $(( $TTL_VALID_FROM_SLOT_NO + 1000 )) \ | |
--fee ${ACTUAL_MIN_FEE} \ | |
${IN_UTXO} \ | |
--tx-out="${DESTINATION_ADDRESS}+${SEND_AMOUNT} lovelace" \ | |
--tx-out="${SOURCE_ADDRESS}+$(( ${IN_BALANCE} - ${ACTUAL_MIN_FEE} - ${SEND_AMOUNT})) lovelace" \ | |
--out-file txbody-ok-fee | |
cardano-cli transaction sign \ | |
--testnet-magic ${NETWORK_MAGIC} \ | |
--signing-key-file ${PAYMENT_SKEY} \ | |
--tx-body-file txbody-ok-fee \ | |
--out-file tx.signed | |
xxd -r -p <<< $(jq .cborHex tx.signed) > tx.submit-api | |
#cardano-cli transaction submit --tx-file ${TOKEN_NAME}.tx.signed --testnet-magic ${NETWORK_MAGIC} | |
curl -X POST \ | |
--header "Content-Type: application/cbor" \ | |
--data-binary @tx.submit-api \ | |
https://submit-api.testnet.dandelion.link/api/submit/tx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment