Skip to content

Instantly share code, notes, and snippets.

@ahaxu
Last active September 9, 2022 20:27
Show Gist options
  • Save ahaxu/caf3b4b6587a6b160707c7d46ec7516c to your computer and use it in GitHub Desktop.
Save ahaxu/caf3b4b6587a6b160707c7d46ec7516c to your computer and use it in GitHub Desktop.
cardano burn token bash script
# Usage:
# $ ./burn.sh $tokenName $payment_address $policy_script_file_path
#
# For eg:
# $ ./burn.sh AhaXuTokenName `cat payment.addr` policy.script
#
# For list of token (for eg token.list) as below
# AAA
# BBB
# CCC
# $ cat token.list | xargs -I$ ./burn.sh $ `cat payment.addr` policy.script
#
tokenName=$1
tokenHex=$(echo -n $tokenName | xxd -b -ps -c 80 | tr -d '\n')
utxo=$(cardano-cli query utxo --address $(cat payment.addr) --mainnet | grep $tokenHex)
txHash=`echo $utxo | awk '{print $1"#"$2}'`
echo "txHash $txHash"
burnfee="0"
burnoutput="0"
burnoutput=1400000
address=$2
script=$3
policyid=`cardano-cli transaction policyid --script-file $script`
echo "policyid $policyid"
slot=$(cardano-cli query tip --mainnet | jq -r '.slot')
echo "building burning raw for tokenName $tokenName | tokenHex $tokenHex"
cardano-cli transaction build --mainnet \
--alonzo-era \
--tx-in "$txHash" \
--tx-out "$address+$burnoutput" \
--mint="-1 $policyid.$tokenHex" \
--minting-script-file $script \
--change-address $address \
--invalid-hereafter $((${slot} + 10000)) \
--witness-override 2 \
--out-file burning.raw
echo "Signing tnx for tokenName $tokenName"
cardano-cli transaction sign --signing-key-file payment.skey --signing-key-file policy.skey --mainnet --tx-body-file burning.raw --out-file burning.signed
echo "Burning ...!"
cardano-cli transaction submit --tx-file burning.signed --mainnet
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment