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 ?
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 ?
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
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 ?
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
Alright, thanks guys.
I tried those on testnet and successfully sent it to alternate addresss.
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
Much appreciated if there a sampleā¦
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.
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
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 ?
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
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!
Awesome!
This script really helps.
Much appreciated you shared this here, hope it will helps the community.
Thank you, that makes us easier to understand and use it
Keep up the wonderful work. Really appreciate it.
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.
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
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
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.
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 ?
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).
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
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
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
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.
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