MINT token with more than 2 txout/txin + calculate min-ADA

Hi,

I am experimenting with tokens.
Is it posible to mint a token with minADA + fee paid by address1 and the token delivered to address2.
If possible what the script should look like ?

1 Like

Yes. I did so in my last project to avoid the mess of having funds and tokens on the same address. In the transaction you would have on tx-in that is your funding address, and two tx-out that is the unused funds going back to the funding address and other the tx-out that has the token(s) and their needed min-ada-value.
This way makes it a lot easier to manage the accounts :slight_smile:

3 Likes

So based on your explaination the script should be like:

cardano-cli transaction build-raw
${tx_in}
ā€“tx-out $(cat key/payment.addr)+${txOut}
ā€“tx-out $destinationAddress+${minADA}+"$tokenamount $policyid.$tokenname"
ā€“mint="$tokenamount $policyid.$tokenname"
ā€“metadata-json-file NFT/metadata.json
ā€“invalid-hereafter $(( ${currentSlot} + 10000))
ā€“fee 0
ā€“out-file tx.tmp

Or would you mind share your script ?

3 Likes

This is how mine looks like:

cardano-cli transaction build-raw
ā€“mary-era
ā€“fee 0
ā€“invalid-hereafter {slotNumber}
ā€“tx-in {TxHash}#{TxIx}
ā€“tx-out $(cat payment.addr)+0
ā€“tx-out {alternative address}+{MinADA}+ā€œ1 {policyid}.{NFTName1} + 1 {policyid}.{NFTName2}ā€
ā€“mint=ā€œ1 {policyid}.{NFTName1} + 1 {policyid}.{NFTName2}ā€
ā€“metadata-json-file metadata.json
ā€“out-file tx.raw

4 Likes

Alright, thanks guys.
I tried those on testnet and successfully sent it to alternate addresss.
image

Next question,
How do you deal with minADA ?
Currently to make sure there is no problem with this transaction so i put 10 ADA there.
Do you have a detail script to calculate everyting on terminal ?

I found this documentation, but honestly i am new to this linux thing and still learning by myself on the line, thats why still confuse and have no idea how to put it on script :sweat_smile:
Much appreciated if there a sampleā€¦

1 Like

The minimum to send a token is 1500000 Lovelace ie 1.5ADA.

In my example above were I am sending two tokens, the minimum for the token address would be 3000000 Lovelace ie 3 ADA.
The rest minus the fee I would be sending them back to the payment address.

1 Like

Thank you for the insight,
But i would like to calculate as minimum as posible just like daedalus did when you tried to sent an asset it will give information the minimum ADA needed.

EDIT: Apologies, the previous version of the post was based on coinSize = 2, but the current network is still using coinSize = 0. The table below is valid for the network as of this posting date.

If there is just one asset in the --tx-out, one can use the following table to find the min-ADA. If there are multiple tokens, then one can use an online min-ADA calculator.

Length in Bytes of Asset Name min-ADA
up to 8 1.444443
9 to 16 1.481480
17 to 24 1.518517
24 to 32 1.555554

If the asset name includes unicode characters, then its length in bytes might be a little larger than the number of characters it contains.

If one wants to calculate min-ADA in a bash shell script when there is only one token, then one can use the formula $(( ((${#NAME} - 1) / 8) * 37037 + 1444443)). For example:

NAME=MyAssetName
MINLOVELACE=$(( ((${#NAME} - 1) / 8) * 37037 + 1444443 ))

echo $MINLOVELACE
# prints 1481480
1 Like

Wonderfull, this is what iā€™m looking for.
Thanks @bwbush
Currently i just need to put 1 token on every txout.
Another question,
Iā€™ve seen your min-ADA calculator, but still confuse to use it, is there any detail explaination each attributes on parameters, properties and results ?
image
Would be great if there is sample of use case to implement those.

I did that in bash to get exact value to use at EasyCNFT.art

THEminUTxOValue=1000000
coinSize=0
numPIDs=1

sumAssetNameLengths=$(cat cnftname | wc -c)

numAssets=1
pidSize=28
utxoEntrySizeWithoutVal=27

adaOnlyUTxOSize=$(( $utxoEntrySizeWithoutVal + $coinSize ))

roundupBytesToWords=$(bc <<< "scale=0; ( $numAssets*12 + $sumAssetNameLengths + $numPIDs*$pidSize + 7 ) / 8")

tokenBundleSize=$(( 6 + $roundupBytesToWords ))

minAda=$(( $(bc <<< "scale=0; $THEminUTxOValue / $adaOnlyUTxOSize") * ( $utxoEntrySizeWithoutVal + $tokenBundleSize ) ))

Hope it helps :slight_smile:

2 Likes

I added documentation for the parameters and three example calculations to the online min-ADA calculator. Hopefully, it is easier to use now. I appreciate your feedback!

3 Likes

Awesome!
This script really helps.
Much appreciated you shared this here, hope it will helps the community.

1 Like

Thank you, that makes us easier to understand and use it :slight_smile:
Keep up the wonderful work. Really appreciate it.

3 Likes

Iā€™ve variant on this question Iā€™ve been experimenting with tokens also.

I want to understand is it possible to MINT with two or more inputs --tx-ins so the opposite problem with a twist.

The scenario is you may not have enough lovelace in an individual UTXO but between the two there is sufficient. Iā€™ve tried and failed so Iā€™m curious to the fundamentals of UTXOs and what is possible.

In my frustration, I tried to simplified the problem to send two UTXOā€™s to another address, without minting , to combine them into a single UTXO minus the fees , but Iā€™ve also failed here.

So my second question when you have multiple UTXOā€™s that you want to combine as inputs and there is NO change, so you want to completely spend everything minus fees. How does that work ? Do you have to commit a transaction and assign Zero as change, or is this automatic or some flag has to be set. I canā€™t get this to work have consistent errors of ValueNotConservedUTxO. Hence, I need to understand whats fundamentally possible what do you do with zero change if anything, do you ignore it or do you have to synthesis it , but that makes no-sense when considering minUTxOValue ?

Iā€™ve tried several approaches writing a wrapper to test things nothing works to date, if I understand minUTxOValue and if there was change the account receiving the change also has to have 1 ADA ? But In the Scenarios Iā€™m trying to construct there is no change there is only one receiving account getting everything minus the fee.

This is the construct for the transaction

TX_FEE=$(cardano-cli transaction calculate-min-fee
ā€“tx-body-file matx.raw
ā€“tx-in-count 2
ā€“tx-out-count 1
ā€“witness-count 1
ā€“testnet-magic 1097911063
ā€“protocol-params-file protocol.json | awk ā€˜{print $1}ā€™)

SENDAMOUNT=$(($AVAILABLE_LOVELACE-$TX_FEE))
cardano-cli transaction build-raw
ā€“mary-era
ā€“fee $TX_FEE
ā€“tx-in $TX_HASH_AND_TXID1
ā€“tx-in $TX_HASH_AND_TXID2
ā€“tx-out $PAYADDR2+$SENDAMOUNT
ā€“invalid-hereafter $INVALIDAFTERSLOT
ā€“out-file matx.raw

After signing and running the script I get the following output

TX_FEE : 173201
INVALIDAFTERSLOT : 26445960
AVAILABLE_LOVELACE: 2814812
SENDAMOUNT: 2641611
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraMary (ApplyTxError [LedgerFailure (UtxowFailure (UtxoFailure (ValueNotConservedUTxO (Value 2814812 (fromList [(PolicyID {policyID = ScriptHash ā€œ6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7ā€},fromList [("",4)])])) (Value 2814812 (fromList )))))])

My thinking is if I can get this working then map it back to the initial minting problem

Anyway many thanks in advance for reading this.

Regards Richard

1 Like

What youā€™re trying is possible and your strategy and script are fine. The problem with the transaction you tried is that one of the inputs has 4 of a token 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7, but the output doesnā€™t. Both the lovelace and the token counts must balance in a non-minting transaction. The error message cryptically reports that. Youā€™ll need either to add the 4 token to the output or to use a token less input.

1 Like

Many thanks for your quick replay , very much appreciated.

As a follow-up is this the lovelace + 2 as below summed to 4 the token count ?

lCaradanoT1:~/cardanoTestNetKeys$ cardano-cli query utxo --address $(cat payment.addr) --testnet-magic 1097911063
TxHash TxIx Amount

63f176c3fe800d8ba75737329e4b6d939c6b44331de46255366d7775b9f2c2fe 0 1407406 lovelace + 2 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7
adf234827b070dd7d15302b0f1d8c09eb62bc2e21136b51695c4160c7c9505a6 0 1407406 lovelace + 2 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7

Could you point me at any documentation that explains the token count and the breakdown from the above output, so I know how you incorporate it ?

I did wonder about the Amount file past plus sign but could not find anything to explain it

Again many thanks your a star

The ā€œSend the new native asset to another addressā€ section of the token documentation shows the format for build-raw and how the output query utxo looks. Basically, the number of tokens are followed by a space, then the policy ID, and finally a period (".") followed by the asset name if the asset is named.

In your example, the asset name was blank: thatā€™s why the error message had [("",4)] in it, which meant that there were 4 tokens with an empty name. Your transaction output should probably read --tx-out $PAYADDR2+$SENDAMOUNT+"4 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7", though there is a chance it might need to have a period at then end like ā€“tx-out $PAYADDR2+$SENDAMOUNT+"4 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7.". (I havenā€™t used assets with blank names, so Iā€™m not sure of the syntax.)

P.S. If you use the --out-file option on query utxo, the results will be stored in a JSON file that might be easier to parse and extract information from (with a tool like jq).

2 Likes

Just to close out my lack of understanding may help others as my original misunderstanding was Iā€™d downloaded from the faucet the NFT option for test ADA which came with this NFT with a blank token name.

This threw me as almost all examples and tutorials begin with the notion of normal ada not test ada which has a blank NFT associated with it. I subsequently went back to faucet and download some normal test ada.

So lessons learned

  1. I was able to consolidate multiples inputs into a single output on a second address with a blank token name with the following, so no period required

SENDAMOUNT=$(($AVAILABLE_LOVELACE-$TX_FEE))
cardano-cli transaction build-raw
ā€“mary-era
ā€“fee $TX_FEE
ā€“tx-in $TX_HASH_AND_TXID1
ā€“tx-in $TX_HASH_AND_TXID2
ā€“tx-out $PAYADDR2+$SENDAMOUNT+"$TOKEN_QUANITY $POLICYID"
ā€“invalid-hereafter $INVALIDAFTERSLOT
ā€“out-file matx.raw

NB Its important to NOTE that the token quantity here is the sum of the number of NFT tokens of the two input transactions in my case this was 4 (2+2) token see below

AMOUNT
1407406 lovelace + 2 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7
1407406 lovelace + 2 6b8d07d69639e9413dd637a1a815a7323c69c86abbafb66dbfdb1aa7

  1. Having minted my first NFT , I was then able to then mint a Second NFT with a different name using remaining Lovelace (change) from the first NFT mint and send the resulting second NFT to a second address like thus

CHANGEAFTERFEE=$(($AVAILABLE_LOVELACE-$TX_FEE))
CHANGE=$(($CHANGEAFTERFEE-$minAda))
cardano-cli transaction build-raw
ā€“mary-era
ā€“fee $TX_FEE
ā€“tx-in $TX_HASH_AND_TXID1
ā€“tx-out $PAYADDR2+$minAda+"$TOKEN_QUANITY $POLICYID.$TOKEN_NAME2"
ā€“tx-out $PAYADDR+$CHANGE+"$TOKEN_QUANITY $POLICYID.$TOKEN_NAME1"
ā€“mint="$TOKEN_QUANITY $POLICYID.$TOKEN_NAME2"
ā€“invalid-hereafter $INVALIDAFTERSLOT
ā€“out-file matx.raw

The result is Iā€™m beginning to understand that balancing the inputs and out puts means all the tokens and NFTā€™s in the seeding transaction. Seems all NFTs need to be assocaited with at least the minimum ada - which makes sense.

Next test is creating multiple NFTS on a single transaction to see the resulting structure.

Again my thanks to bwbush and all above.

Regards Damfoolcat

2 Likes

Great testing and result there, hope it will helps community by reaching this thread.
I changed the thread name to make others more easy to find solution with the same topic.

1 Like

FYI: Version 1.27.0 of cardano-cli has a command for computing the minimum value:

Usage: cardano-cli transaction calculate-min-value (--genesis FILE | 
                                                    --protocol-params-file FILE)
                                                    --multi-asset VALUE
  Calculate the minimum value for a transaction
3 Likes