0

On the Offchain code I am trying to mint a token using the following snippet

Constraints.mustMintValueWithRedeemer r (assetClassValue cTk 1)

In the validation code of the minting script I am trying to verify if only one token was minted

tkMinted :: Value
tkMinted = txInfoMint info

But when I try to check the number of currencies minted using the following code

symbols tkMinted

I see there are more than one type of currency in the value list. Is this expected ?

Here is a detailed snippet

--------------
-- Policy
--------------

data UsrParams = UsrParams {
    tk :: !TokenName
  , c :: !CurrencySymbol
} deriving (Show, Generic, FromJSON, ToJSON, ToSchema)
  
PlutusTx.makeIsDataIndexed ''UsrParams [('UsrParams , 0)]
PlutusTx.makeLift ''UsrParams


{-# INLINABLE usrPolicy #-}
usrPolicy :: UsrParams -> BuiltinData -> Contexts.ScriptContext -> Bool
usrPolicy params r ctx = traceIfFalse  "Failed to mint!" ( tkMinted == (Value.singleton (c params) (tk params) 1) )
  where
    info :: V2LedgerApi.TxInfo    
    info = Contexts.scriptContextTxInfo ctx

    currencySymbol :: CurrencySymbol
    currencySymbol = c params

    tkMinted :: Value
    tkMinted = V2LedgerApi.txInfoMint info


---------------------
-- Test Code
---------------------

asset :: AssetClass
asset = AssetClass (usrCurrencySymbol, TokenName "T1")

getCoins :: Integer -> Value
getCoins i = assetClassValue asset i


-------------
-- Endpoint
-------------

mintEP :: () -> Contract w TradeSchema Text ()
mintEP _ = do
    let 
        val     = getCoins 1
        lookups = Constraints.plutusV2MintingPolicy (usrMintingPolicy $ PlutusTx.toBuiltinData usrParams )
        tx      = Constraints.mustMintValue val 

    ledgerTx <- submitTxConstraintsWith @Void lookups tx
    void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
    Contract.logInfo @String $ printf "forged %s" (show val)
2
  • I don't understand why you're using <> here, is there another asset involved?
    – james
    Commented Nov 15, 2022 at 21:21
  • James - I have edited my question. I also added more snippets. The minting still fails
    – munx
    Commented Nov 17, 2022 at 16:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.