I made that same assumption, here’s a script I created and just used yesterday to mint with a known fee which does not kick any errors…(it’s still a little rough but I’ll clean it up as I’m able/have time)…you then just need to sign and send, just remember to sign with 2 witnesses, your wallet and your policy skey file:
#!/bin/bash
read -p 'Minting Wallet: ' MINT_ADDR
read -p 'Token Name: ' nftName
read -p 'Token Qty: ' tknQTY
read -p 'Slot: ' nftSlot
mintAddr=$(cat wallets/${MINT_ADDR}.addr) # the answer to Minting Wallet should be the filename of a file ending in .addr residing in a wallets folder inside this folder, and it only contains the wallets address. Same wallet should have an skey and vkey file by the same wallet name in the same wallets folder for these scripts to work
LOGFOLDER=logs/payments # optional, keep files clean and log them in a logs folder in this folder
TIMESTAMP=`date "+%Y-%m-%d_%H-%M-%S"`
# Get UTxO
$CARDANO_CLI query utxo \
--address ${mintAddr} \
--testnet-magic ${TESTNET_MAGIC_NUM} > fullUtxo.out
tail -n +3 fullUtxo.out | sort -k3 -nr > balance.out
cat balance.out
tx_in=""
total_balance=0
while read -r utxo; do
in_addr=$(awk '{ print $1 }' <<< "${utxo}")
idx=$(awk '{ print $2 }' <<< "${utxo}")
utxo_balance=$(awk '{ print $3 }' <<< "${utxo}")
total_balance=$((${total_balance}+${utxo_balance}))
echo TxHash: ${in_addr}#${idx}
echo ADA: ${utxo_balance}
tx_in="${tx_in} --tx-in ${in_addr}#${idx}"
done < balance.out
txcnt=$(cat balance.out | wc -l)
echo Total ADA balance: ${total_balance}
echo Number of UTXOs: ${txcnt}
echo TXIn: ${tx_in}
newbal=$((${total_balance}-4000000)) # <-- subtracting the 2 following instances of token utxos
# Draft the tx
$CARDANO_CLI transaction build-raw \
${tx_in} \
--tx-out ${mintAddr}+${newbal} \
--tx-out ${mintAddr}+2000000+"1 some_other_already_mintedTokenID.NAME" \
--tx-out ${mintAddr}+2000000+"${tknQTY} $(cat nativetokens/${nftName}.id).${nftName}" \
--invalid-hereafter 0 \
--fee 0 \
--mint="${tknQTY} $(cat nativetokens/${nftName}.id).${nftName}" \
--minting-script-file nativetokens/${nftName}.script \
--metadata-json-file nativetokens/${nftName}.json \
--alonzo-era \
--out-file tx_nft.tmp
# Calculate the fee
fee=$($CARDANO_CLI transaction calculate-min-fee \
--tx-body-file tx_nft.tmp \
--tx-in-count ${txcnt} \
--tx-out-count 3 \ # <-- make sure your count is accurate
--witness-count 2 \
--testnet-magic ${TESTNET_MAGIC_NUM} \
--protocol-params-file params.json | awk '{ print $1 }')
echo fee: $fee
txOut=$((${total_balance}-${fee}-4000000)) # again, account for the 2 (or other) tx-outs
echo Change Output: ${txOut}
# Build the TX
echo "=========================="
echo "....Building for: ${tx_in}"
echo "=========================="
echo ""
$CARDANO_CLI transaction build-raw \
${tx_in} \
--tx-out ${mintAddr}+${txOut} \
--tx-out ${mintAddr}+2000000+"1 some_other_already_mintedTokenID.NAME" \
--tx-out ${mintAddr}+2000000+"${tknQTY} $(cat nativetokens/${nftName}.id).${nftName}" \
--invalid-hereafter ${nftSlot} \
--fee ${fee} \
--mint="${tknQTY} $(cat nativetokens/${nftName}.id).${nftName}" \
--minting-script-file nativetokens/${nftName}.script \
--metadata-json-file nativetokens/${nftName}.json \
--alonzo-era \
--out-file tx_nft.raw
mv fullUtxo.out $LOGFOLDER/${TIMESTAMP}_fullUtxo.out
mv balance.out $LOGFOLDER/${TIMESTAMP}_balance.out
mv tx_nft.tmp $LOGFOLDER/${TIMESTAMP}_tx_nft.tmp
cp tx_nft.raw $LOGFOLDER/${TIMESTAMP}_tx_nft.raw
echo ""
echo "===== Finished ====="
echo "Get and Move tx_nft.raw file to Cold for signing"
echo ""
and to sign it is something like this:
#!/bin/bash
read -p 'Signing Wallet: ' WALLET_NAME
$CARDANO_CLI transaction sign \
--tx-body-file tx_nft.raw \
--signing-key-file wallets/${WALLET_NAME}.skey \
--signing-key-file wallets/policy.skey \
--testnet-magic ${TESTNET_MAGIC_NUM} \
--out-file tx_nft.signed
rm tx_nft.raw
echo ""
echo "===== Finished ====="
echo "move tx_nft.signed back to node for sending!"
where wallets/policy.skey is your policy skey file whereever it lives. Then just send the resulting file using something like this:
#!/bin/bash
LOGFOLDER=logs/sent
TIMESTAMP=`date "+%Y-%m-%d_%H-%M-%S"`
$CARDANO_CLI transaction submit \
--tx-file tx_nft.signed \
--testnet-magic ${TESTNET_MAGIC_NUM}
mv tx_nft.signed $LOGFOLDER/${TIMESTAMP}_tx_nft.signed
echo ""
echo "======= Finished ======"
echo "TX Sent! Check for errors ^"
echo ""