Open HT-Moh opened 2 years ago
Hi @HT-Moh, the steps should be as follows:
1) Create the threaded NFTs for the counter or counters. More counter outputs will allow for concurrency and high availability, I currently use 10, this way I am sure I will always have a counter available for use.
To create the threaded NFTs for the counters you must use this script:
checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
[(_, tn', amt)] -> tn' == tn && amt == 10 -- | Change to 10 for the purpose of created 10 identity tokens for the Counter contract.
_ -> False
Notice I hardcoded 10 tokens, because I have ten counters, change this number for the number of counters you want to make. It is important that this number matches the number of counters you want to use and that all of the tokens are placed inside the contract, otherwise, the uniqueness of the NFTs can not be guaranteed.
2) After you create the threaded tokens for the counters, then you must compile the plutus-horrocubes-counter script using the policy id and token name of those threaded counters.
cabal run plutus-horrocubes-counter $THREADED_TOKEN_CURRENCY_SYMBOL $THREADED_TOKEN_ASSET_NAME $PAYMENT_HASH counter.plutus
Now you should be able to use the counters, you can first try this by increasing the counter once directly:
cardano-cli transaction build \
--alonzo-era \
--change-address $PAYMENT_ADDRESS \
--tx-in $TXHASH#$TXID \
--tx-in-collateral $TXHASH#$TXID \
--tx-in $COUNTER_TXHASH#$COUNTER_TXID \
--tx-in-script-file counter.plutus \
--tx-in-datum-file datum0.datum \
--tx-in-redeemer-file datum0.datum \
--tx-out "$COUNTER_CONTRACT_ADDRESS+1758582+ 1 $(cat $THREADED_TOKEN_CURRENCY_SYMBOL).$(cat
$THREADED_TOKEN_ASSET_NAME)" --tx-out-datum-embed-file datum1.datum --required-signer policy.skey --mainnet --out-file transaction.raw
I am not near my dev environment so I can't test this, but should be something along those lines, notice the following :
--tx-out-datum-embed-file datum1.datum
The contract needs both the current and the new datum value to perform the validations, so you must provide both datum values (providing datum hash is not enough for this contract). This si done via --tx-in-datum-file and --tx-out-datum-embed-file.
Once you can be sure you can increase the counter contract, then we move to the next step.
3) Lets now compile the MintingScriptWithCounter.hs script.
cabal run plutus-horrocubes-tokens-counter $THREADED_TOKEN_CURRENCY_SYMBOL $THREADED_TOKEN_ASSET_NAME $PAYMENT_HASH mintAssets.plutus
Both scripts take the same parameters. The threaded tokens and the signing key, key could be the same or different, I use the counters in several collections, so I change the key here for each collection, but it could be the same key you used for the counter script if you want. $THREADED_TOKEN_CURRENCY_SYMBOL and $THREADED_TOKEN_ASSET_NAME have to be the same.
After you compile this script, you are ready to mint. As you can see, to mint you must invoke the two scripts, the counter script, and the minter script. You must increase the datum value and then make sure the NFT you are minting has as postfix on the token name the new counter value in hexadecimal, for example, if the new counter value is 1, the token must end with '00000001'
This is an example of one of my minting transactions:
cardano-cli transaction build --alonzo-era --change-address $ADDRESS --tx-in $UTXO#$UTXO_ID --tx-in-collateral $COLLATERAL_UTXO#$COLLATERAL_UTXO_ID --tx-in $COUNTER_UTXO#$COUNTER_UTXO_ID --tx-in-script-file counter.plutus --tx-in-datum-file b9475874-691d-48de-ae04-de35aec036c1.datum --tx-in-redeemer-file b9475874-691d-48de-ae04-de35aec036c1.datum --tx-out $COUNTER_CONTRACT_ADDRESS+1758582+ 1 cde924ed9494ed6be4ea7d4108588a86cbcf0a9a4ca4d5da19dc7aab.HorrocubesMinterAgent --tx-out-datum-embed-file 8eb78cd2-4952-4633-881d-17f26005a308.datum --required-signer horrocubes.skey --tx-out $ADDRESS+1448244+1 cd743f819701ba9123b4a17d587aaf1342d19fee896453c6ad9c3825.KnightOfSwordsXmas00092xB3333339 --mint 1 cd743f819701ba9123b4a17d587aaf1342d19fee896453c6ad9c3825.KnightOfSwordsXmas00092xB3333339 --minting-script-file mintAssets.plutus --mint-redeemer-value [] --protocol-params-file protocol.json --json-metadata-no-schema --metadata-json-file 2396a911-867b-4f00-afa2-35d80eb26518.metadata --mainnet --out-file 90fc5c7d-8fc1-4b86-ad52-14f22e602d76.raw
This is my counter contract threaded token:
cde924ed9494ed6be4ea7d4108588a86cbcf0a9a4ca4d5da19dc7aab.HorrocubesMinterAgent
Also, notice the token name on the mint part of the transaction:
KnightOfSwordsXmas00092xB3333339
B3333339 is the hex value of that particular counter.
Let me know if you manage to make it work, I am on holiday right now, and don't have access to my dev environment. If you are still having problems I will create a detailed step by step guide on how to set this up once I come back. In the meantime, you can check this video:
https://www.youtube.com/watch?v=vHraLcvECmQ
And this discussion on the Cardano forums:
https://forum.cardano.org/t/mary-era-nfts-alonzo-era-nfts-which-are-better/82034/2
This is a transaction of one of the mints using this contract:
https://cardanoscan.io/transaction/0dc6e9705685bfe270d0994475512e87d61910cb28f0f6d733744575e8d90553
@AngelCastilloB Thank you. I will try this and let you know. Have a good holiday and happy new year :+1:
Sorry one more thing thing, there is no main function forUtxoMintingScript.hs
, this script is not used at all inside :
Do I need to create plutus-utxo-minthing.hs with the following code , then compile and run the script, correct?
import Cardano.Api hiding (TxId)
import Data.String (IsString (..))
import Ledger
import Ledger.Bytes (getLedgerBytes)
import Prelude
import System.Environment (getArgs)
import Horrocubes.UtxoMintingScript
main :: IO ()
main = do
[utxo'] <- getArgs
let utxo = parseUTxO utxo'
nftPolicyFile = "scripts/nft-mint-policy.plutus"
otherPolicyFile = "scripts/other-mint-policy.plutus"
nftPolicyResult <- writeFileTextEnvelope nftPolicyFile Nothing $ apiNFTMintScript utxo
case nftPolicyResult of
Left err -> print $ displayError err
Right () -> putStrLn $ "wrote NFT policy to file " ++ nftPolicyFile
otherPolicyResult <- writeFileTextEnvelope otherPolicyFile Nothing apiOtherMintScript
case otherPolicyResult of
Left err -> print $ displayError err
Right () -> putStrLn $ "wrote other policy to file " ++ otherPolicyFile
parseUTxO :: String -> TxOutRef
parseUTxO s =
let
(x, y) = span (/= '#') s
in
TxOutRef (TxId $ getLedgerBytes $ fromString x) $ read $ tail y
Oh, I just realized I didn't upload the app script, you also need to pass the asset name. You can take the script from here:
https://github.com/Horrocubes/cardano-nft-factory/blob/main/app/plutus-horrocubes-tokens.hs
and replace:
import Horrocubes.MintingScript
for:
import Horrocubes.UtxoMintingScript
Alternatively, you can also use this repo for that first step:
https://github.com/Horrocubes/cardano-nft-factory
And change this function:
checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
[(_, tn', amt)] -> tn' == tn && amt == 1
_ -> False
for
checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
[(_, tn', amt)] -> tn' == tn && amt == 10 -- | Change to 10 for the purpose of created 10 identity tokens for the Counter contract.
_ -> False
Or with the number of counter tokens you need :)
Happy new year to you too!
Happy new year :-) unfortunately I still can not figure this out maybe the end of the year ;-) Please find below the all the steps and comments inline and errors
I did the change as you suggest to the script
plutus-horrocubes-tokens.hs
and everything compiles.
echo '{"constructor":0,"fields":[{"int":0},{"int":111111189}]}' >> datum0.datum echo '{"constructor":0,"fields":[{"int":111111190},{"int":222222379}]}' >> datum1.datum
############################################################
# Currency symbol
THREADED_TOKEN_CURRENCY_SYMBOL="CURRENCY SYMBOL"
# Asset name
THREADED_TOKEN_ASSET_NAME="ASSET NAME" ## Currency simbol and token name should be the same.
# Payment address path
PAYMENT_ADDRESS="Payment address path"
# Verification key
PAYMENT_VKEY="PATH TO VKEY"
# Verification key hash
PAYMENT_HASH=$(cardano-cli address key-hash --payment-verification-key-file $PAYMENT_VKEY)
# Plutus script name which use UtxoMintingScript (going with 10 for counter)
PLUTUS_TOKEN_SCRIPT=plutus-horrocubes-tokens
# Chose UTXO hash
UTXO="UTXO VALUE"
UTXO_ID="0"
# TOKEN AMOUNT
TOKENAMOUNT=10 # Is this correct
# output
OUTPUT=1758582
# Build counter script
cabal run $PLUTUS_TOKEN_SCRIPT $UTXO_HASH#0 $THREADED_TOKEN_ASSET_NAME $PLUTUS_TOKEN_SCRIPT.plutus
# POLICY ID
POLICY_ID=$(cardano-cli transaction policyid --script-file $PLUTUS_TOKEN_SCRIPT.plutus)
cardano-cli address build --payment-script-file $PLUTUS_TOKEN_SCRIPT.plutus --mainnet --out-file $PLUTUS_TOKEN_SCRIPT.addr
cardano-cli transaction build \
--alonzo-era \
--change-address $PAYMENT_ADDRESS \
--tx-in-collateral $UTXO#$UTXO_ID \
--tx-in $UTXO#$UTXO_ID \
--tx-out $(cat $PLUTUS_TOKEN_SCRIPT.addr)+$OUTPUT+"$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX" \
--mint "$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX" \
--mint-script-file $PLUTUS_TOKEN_SCRIPT.plutus \
--mint-redeemer-value [] \
--protocol-params-file parameters.json \
--out-file $PLUTUS_TOKEN_SCRIPT.build \
--mainnet
## Command failed: transaction build Error: The following scripts have execution failures:
## the script for policyId 0 (in the order of the PolicyIds) failed with:
## The Plutus script evaluation failed: An error has occurred: User error:
## The provided Plutus code called 'error'.
## Script debugging logs: Wrong amount minted
## Pd
The tx failed is the transaction build correctly? the TOKENAMOUNT should not be equal to the counter?
# Get the utxos
cardano-cli query utxo --address $(cat $PAYMENT_ADDRESS) --mainnet
# Choose new uxto
UTXO="UTXO VALUE"
#
UTXO_ID="0"
#
COUNTER_TXHASH="" # From where can I get the counter tx hash
COUNTER_TXID=""
# Plutus script name plutus-horrocubes-counter
PLUTUS_TOKEN_SCRIPT=plutus-horrocubes-counter
# Build counter script
cabal run $PLUTUS_TOKEN_SCRIPT $THREADED_TOKEN_CURRENCY_SYMBOL $THREADED_TOKEN_ASSET_NAME $PAYMENT_HASH $PLUTUS_TOKEN_SCRIPT.plutus
# Build Script address
cardano-cli address build --payment-script-file $PLUTUS_TOKEN_SCRIPT.plutus --mainnet --out-file $PLUTUS_TOKEN_SCRIPT.addr
# SET THE SCRIPT ADDRESS
COUNTER_CONTRACT_ADDRESS=$(cat $PLUTUS_TOKEN_SCRIPT.addr)
cardano-cli transaction build \
--alonzo-era \
--change-address $PAYMENT_ADDRESS \
--tx-in $UTXO#$UTXO_ID \
--tx-in-collateral $UTXO#$UTXO_ID \
--tx-in $COUNTER_TXHASH#$COUNTER_TXID \
--tx-in-script-file $COUNTER_SCRIPT \
--tx-in-datum-file datum0.datum \
--tx-in-redeemer-file datum0.datum \
--tx-out "$COUNTER_CONTRACT_ADDRESS+1758582+ 1 $(cat $THREADED_TOKEN_CURRENCY_SYMBOL).$(cat $THREADED_TOKEN_ASSET_NAME)" \
--tx-out-datum-embed-file datum1.datum \
--required-signer $PAYMENT_KEY \
--mainnet \
--out-file transaction.raw
plutus-horrocubes-tokens-counter.hs
$ASSET_MINTER=mintAssets.plutus
cabal run plutus-horrocubes-tokens-counter $THREADED_TOKEN_CURRENCY_SYMBOL $THREADED_TOKEN_ASSET_NAME $PAYMENT_HASH $ASSET_MINTER
MINTER_POLICY_ID=$(cardano-cli transaction policyid --script-file $PLUTUS_TOKEN_SCRIPT.plutus)
cardano-cli transaction build \
--alonzo-era \
--change-address $ADDRESS \
--tx-in $UTXO#$UTXO_ID \
--tx-in-collateral $COLLATERAL_UTXO#$COLLATERAL_UTXO_ID \
--tx-in $COUNTER_UTXO#$COUNTER_UTXO_ID \
--tx-in-script-file $COUNTER_SCRIPT \
--tx-in-datum-file $DATATUM_FILE \
--tx-in-redeemer-file $DATATUM_FILE \
--tx-out $COUNTER_CONTRACT_ADDRESS+1758582+ 1 cde924ed9494ed6be4ea7d4108588a86cbcf0a9a4ca4d5da19dc7aab.HorrocubesMinterAgent ## From where which script comes this policy ID
--tx-out-datum-embed-file 8eb78cd2-4952-4633-881d-17f26005a308.datum ## old datum json file
--required-signer $PAYMENT_KEY
--tx-out $ADDRESS+1448244+1 $MINTER_POLICY_ID.KnightOfSwordsXmas00092xB3333339 ## From where comes this policy ID
--mint 1 $MINTER_POLICY_ID.KnightOfSwordsXmas00092xB3333339 ## same as above
--minting-script-file $ASSET_MINTER
--mint-redeemer-value []
--protocol-params-file protocol.json
--json-metadata-no-schema
--metadata-json-file 2396a911-867b-4f00-afa2-35d80eb26518.metadata
--mainnet
--out-file 90fc5c7d-8fc1-4b86-ad52-14f22e602d76.raw
in your first comment your have the argument $COUNTER_TXHASH#$COUNTER_TXID in your txs plutus-horrocubes-counter
, but in this stage I still didnt't submit any SC, so I don't have utxos locked ?
I assume with a counter value 2 I need to build min 3 transactions, correct ?
Hi @HT-Moh, yes token count should be equal to counter and the value hardcoded in the contract:
--mint "$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX"
Are you sure the token name must be passed as a hex string? this seems strange to me, also this may be causing the script to fail because it can't match the value you used as a token name to compile the script with the hex string. I read in your other comment that the new cli version requires token name as a hex string, are you sure about this?, this seems like a breaking change for all the infrastructure developed already out there.
--tx-out $(cat $PLUTUS_TOKEN_SCRIPT.addr)+$OUTPUT+"$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX"
Also, in this line it seems you are depositing the 10 tokens into the script address, but remember, you must only deposit one token per utxo, the way I did it was to mint the 10 tokens and deposit them on a wallet, then manually placed each token in a different eutxo with the right datum, you could do it in the mint transaction, but make sure each token goes to a different eUTXO with the current starting datum value.
COUNTER_TXHASH="" # From where can I get the counter tx hash
Once you mint the 10 tokens and they are in different outputs you can query the script address:
cardano-cli query utxo --address $PLUTUS_TOKEN_SCRIPT_ADDR --mainnet
And you will have your 10 eUTXOs listed there with they tx hash and index.
--tx-out $COUNTER_CONTRACT_ADDRESS+1758582+ 1 cde924ed9494ed6be4ea7d4108588a86cbcf0a9a4ca4d5da19dc7aab.HorrocubesMinterAgent ## From where which script comes this policy ID
This is our threaded tokens, so the policy id is THREADED_TOKEN_CURRENCY_SYMBOL, and HorrocubesMinterAgent is THREADED_TOKEN_ASSET_NAME
--tx-out $ADDRESS+1448244+1 $MINTER_POLICY_ID.KnightOfSwordsXmas00092xB3333339 ## From where comes this policy ID
MINTER_POLICY_ID is the policy id from the MintingScriptWithCounter, this is the mint script for your actual collection.
Hi @AngelCastilloB when I don't use hex I get the error
option --tx-out:
unexpected 'N'
expecting alphanumeric asset name, white space, "+" or end of input
cardano-cli 1.33.0 - linux-x86_64 - ghc-8.10
git rev 28c34d813b8176afc653d6612d59fdd37dfeecfb
@AngelCastilloB
I am still having problem to build the first transaction I got "Script debugging logs: Wrong amount minted
# Chose UTXO hash
UTXO="UTXO VALUE"
UTXO_ID="0"
# TOKEN AMOUNT
TOKENAMOUNT=1 # changing to the counter value which 2 it didn't work neither
# output
OUTPUT=1758582
# Build counter script
cabal run $PLUTUS_TOKEN_SCRIPT $UTXO_HASH#0 $THREADED_TOKEN_ASSET_NAME $PLUTUS_TOKEN_SCRIPT.plutus
# POLICY ID
POLICY_ID=$(cardano-cli transaction policyid --script-file $PLUTUS_TOKEN_SCRIPT.plutus)
cardano-cli address build --payment-script-file $PLUTUS_TOKEN_SCRIPT.plutus --mainnet --out-file $PLUTUS_TOKEN_SCRIPT.addr
cardano-cli transaction build \
--alonzo-era \
--change-address $PAYMENT_ADDRESS \
--tx-in-collateral $UTXO#$UTXO_ID \
--tx-in $UTXO#$UTXO_ID \
--tx-out $PAYMENT_ADDRESS+$OUTPUT+"$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX" \
--mint "$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX" \
--mint-script-file $PLUTUS_TOKEN_SCRIPT.plutus \
--mint-redeemer-value [] \
--protocol-params-file parameters.json \
--out-file $PLUTUS_TOKEN_SCRIPT.build \
--mainnet
Command failed: transaction build Error: The following scripts have execution failures: the script for policyId 0 (in the order of the PolicyIds) failed with: The Plutus script evaluation failed: An error has occurred: User error: The provided Plutus code called 'error'. Script debugging logs: Wrong amount minted Pd
checkMintedAmount :: Bool
checkMintedAmount = case flattenValue (txInfoMint info) of
[(_, tn', amt)] -> tn' == tn && amt == 2 -- | Change to 10 for the purpose of created 10 identity tokens for the Counter contrack.
_ -> False
I am getting always amount not Now I am not sure anymore how to mint the 2 tokens assign the correct datum.
@HT-Moh if you can share with me the command you are using to compile the script, and the CLI command you are using to issue the mint transaction with the variables resolved (without the $ variables but the actual values) so I can understand better the issue you are having.
Hi @AngelCastilloB
I am using the following commands:
cabal build
cabal run plutus-horrocubes-tokens 41d5809207b52e3492b0583338efddc358e340bb2c1b4f97ba78429ac71822d2#0 NewAgeMonsters plutus-horrocubes-tokens.plutus
POLICY_ID=$(cardano-cli transaction policyid --script-file plutus-horrocubes-tokens.plutus)
cardano-cli address build --payment-script-file plutus-horrocubes-tokens.plutus --mainnet --out-file plutus-horrocubes-tokens.addr
TOKENNAME_HEX=$(xxd -pu <<< "NewAgeMonsters")
cardano-cli transaction build \
--alonzo-era \
--change-address addr1qyd2hwd4w8qmtz0u6eh5f05hefwh9yemrfgtsacm626w4lvj4x8te92y27vez25vqdfvpwpy0yx05waqpupn7xh09srq3aux7p \
--tx-in 41d5809207b52e3492b0583338efddc358e340bb2c1b4f97ba78429ac71822d2#0 \
--tx-in-collateral 41d5809207b52e3492b0583338efddc358e340bb2c1b4f97ba78429ac71822d2#0 \
--tx-out addr1qyd2hwd4w8qmtz0u6eh5f05hefwh9yemrfgtsacm626w4lvj4x8te92y27vez25vqdfvpwpy0yx05waqpupn7xh09srq3aux7p+2000000+"1 $POLICY_ID.$TOKENNAME_HEX" \
--mint "$TOKENAMOUNT $POLICY_ID.$TOKENNAME_HEX" \
--mint-script-file plutus-horrocubes-tokens.plutus \
--mint-redeemer-value [] \
--protocol-params-file parameters.json \
--out-file plutus-horrocubes-tokens.build \
--mainnet
let me know if you need anything else, I really appreciate your help thank you .
plutus-horrocubes-tokens creates the plutus script for the minting of the NFTs of the collection, but you must first create the threaded tokens that will go inside the counters, and then initialize the counter contracts with those tokens.
In which step are you right now? did you already minted the threaded tokens and add them inside the counter contract?
No I didn't minted the threaded tokens and add them inside the counter contract. how can I do that ? is this done outside of this scripts? My understanding was that first step is building the counter as my first comment (this tx succeed and ADA is locked, but I assume it's not correct), after your reply I understood that all steps are:
Hi, @HT-Moh I don't see that the tokens were created on that transaction (https://cardanoscan.io/address/714504b7788c203abae23a143bce512641bcb97cf63d71a1419c228ef7), also I would suggest using the testnet for the time being until you can get the whole procedure down to avoid losing real ADA.
I would also suggest you watch this video:
https://www.youtube.com/watch?v=6VbhY162GQA
Is from the Plutus pioneer program, here Lars Brünjes explain some key concepts about native assets and minting policies.
When I have some time I will upgrade my Cardano node version and test this again while recoding every command and step and share it here with you.
Hi @AngelCastilloB No token, I think the transaction is done incorrectly, however it has a balance of 20 ADA which I am sure if there is a possibility to get it back. anyway for the moment I switched to testnet. Thank you so much and I am waiting for your recording.
Hello I am trying to use your SC to create a unique collection of NFTs, and my issue is I am not sure how to build this txs. Here is what I done.
I was able to initialize the counter script with the following steps
The next thing I tried is to use the token with counter to make a NFT but I got an error
cabal run plutus-horrocubes-tokens-counter $CURRENCY_SYMBOL $NFT_NAME $PAYMENT_HASH token-with-counter.plutus
I am sure I am missing something here, and I appreciate your help-