IntersectMBO / plutus-apps

The Plutus application platform
Apache License 2.0
305 stars 213 forks source link

"The second data argument, does not decode to a context" when minting NFT with Mesh #935

Closed danielNg25 closed 1 year ago

danielNg25 commented 1 year ago

This my script for minting NFT:

{-# INLINABLE mkPolicy #-}
mkPolicy :: BuiltinData -> PlutusV2.ScriptContext -> Bool
mkPolicy _ ctx = traceIfFalse "wrong amount minted" checkNFTAmount

  where
    info :: PlutusV2.TxInfo
    info = PlutusV2.scriptContextTxInfo ctx

    -- hasUTxO :: Bool
    -- hasUTxO = any (\i -> PlutusV2.txInInfoOutRef i == mpTxOutRef r) $ PlutusV2.txInfoInputs info

    checkNFTAmount :: Bool
    checkNFTAmount = case Value.flattenValue (PlutusV2.txInfoMint info) of
       [(cs, tn', amt)] -> cs  == ownCurrencySymbol ctx && tn' == PlutusV2.TokenName "" && amt == 1
       _                -> False

I'm using Mesh to minting NFT with that script

    const walletAddr = wallet.getPaymentAddress();
    const addressUtxo: UTxO[] = await provider.fetchAddressUTxOs(walletAddr);

    const redeemer: Partial<Action> = {
        tag: "MINT",
        data: {
            alternative: 0,
            fields: [],
        },
    };

    const assetMetadata: AssetMetadata = {
        name: "MyNFT",
        image: "https://picsum.photos/200",
        mediaType: "image/jpg",
        description: "This NFT is minted by me.",
    };

    const asset: Mint = {
        assetName: "MyNFT",
        assetQuantity: "1",
        metadata: assetMetadata,
        label: "721",
        recipient: walletAddr,
    };

    // Mint NFT

    const tx = new Transaction({ initiator: wallet });

    tx.mintAsset(script, asset, redeemer);
    tx.setCollateral([addressUtxo[0]]);

    const unsignedTx = await tx.build();
    const signedTx = await wallet.signTx(unsignedTx, true);
    try {
        const txHash = await wallet.submitTx(signedTx);
        console.log(txHash);
    } catch (e) {
        console.log(e);
    }

Unfortunately, it returned with this error:

transaction submit error ShelleyTxValidationError ShelleyBasedEraBabbage 
(ApplyTxError 
[UtxowFailure 
(UtxoFailure 
(FromAlonzoUtxoFail 
(UtxosFailure 
(ValidationTagMismatch 
(IsValid True) 
(FailedUnexpectedly 
(PlutusFailure \\\"\\\\nThe 2 arg plutus script (PlutusScript PlutusV2 ScriptHash \\\\\\\"77f807bc9403ef0177cc2a9956bfd5628ee649680041ccf48a198fc0\\\\\\\") fails.
\\\\nCekError An error has occurred:  
User error:\\\\nThe machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
\\\\nThe protocol version is: ProtVer {pvMajor = 7, pvMinor = 0}\\\\nThe redeemer is: Constr 0 []\\\\
nThe second data argument, does not decode to a context

Does anyone faced this error before, what's wrong with my script?

berewt commented 1 year ago

It doesn't look as a plutus-apps related error. Maybe asking about it on cardano stack exchange (https://cardano.stackexchange.com) would be a better option.