<p>I hope this answer doesn't come too late.</p>
<p>the problem is that you are trying to use a contract meant to validate a spending of an utxo for minting instead.</p>
<p>when used for minting you DO NOT need a datum.</p>
<p>datums are only used for spending scripts.</p>
<p>what happens here is that the node only passes 2 arguments to the script.
which implies the script is only <strong>partially applied</strong>; hence it returns a new function, without never throwing an error.</p>
<p>not throwing an error causes the node to think the contract agreed to the transaction, and proceeded.</p>
<p>the fix is easy.</p>
<p>you just want to remove the datum from the contract definition.</p>
<p>so your contract would look like this:</p>
<pre class="lang-typescript prettyprint-override"><code>export const mintNFT = pfn(
  [redeemer.type, PScriptContext.type],
  bool
)((message, ctx) =&gt; {
  return pBool(false);
});
</code></pre>

CC BY-SA 4.0
2024-01-05T16:57:01.123Z
2024-01-05T16:57:01.123Z
Michele Nuzzi
<p>I'm trying to run validations before minting an asset/nft on cardano. I have written the policy script using plu-ts and transactions using mesh sdk.</p>
<p><strong>Script</strong></p>
<pre><code>export const mintNFT = pfn(
  [datum.type, redeemer.type, PScriptContext.type],
  bool
)((datum, message, ctx) =&gt; {
  return pBool(true);
});
</code></pre>
<p><strong>Transaction</strong></p>
<pre><code>const script: PlutusScript = {
  code: nftScriptCbor,
  version: &quot;V2&quot;,
};

const recipient = await wallet.getChangeAddress();

const redeemer: Partial&lt;Action&gt; = {
  tag: &quot;MINT&quot;,
};

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

const metadata: AssetMetadata = {
  name: &quot;Test Token&quot;,
  description: &quot;This is a test nft&quot;,
  image: &quot;ipfs://&quot;,
  mediaType: &quot;image/jpg&quot;,
};

const asset: Mint = {
  assetName: &quot;MeshToken&quot;,
  assetQuantity: &quot;1&quot;,
  metadata,
  label: &quot;721&quot;,
  recipient,
};

const myUTxOs = await wallet.getUtxos();
tx.setCollateral(myUTxOs);

tx.mintAsset(script, asset, redeemer);

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

return txHash;
</code></pre>
<p>The issue is that it mints the NFT, but doesn't run the validations. Although in transaction, it shows that contract is executed, but even if I return false from script, it still gets minted.</p>
<pre><code>export const mintNFT = pfn(
  [datum.type, redeemer.type, PScriptContext.type],
  bool
)((datum, message, ctx) =&gt; {
  return pBool(false);
});
</code></pre>
<p>Can someone please explain how can I resolve this issue?</p>

<minting><mesh><mintingpolicy><plu-ts>
Mint an NFT using policy script on cardano
# Mint an NFT using policy script on cardano

(Asked by: username_0 on 2023-11-23)

I'm trying to run validations before minting an asset/nft on cardano. I have written the policy script using plu-ts and transactions using mesh sdk.
Script
export const mintNFT = pfn(
  [datum.type, redeemer.type, PScriptContext.type],
  bool
)((datum, message, ctx) => {
  return pBool(true);
});

Transaction
const script: PlutusScript = {
  code: nftScriptCbor,
  version: "V2",
};

const recipient = await wallet.getChangeAddress();

const redeemer: Partial = {
  tag: "MINT",
};

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

const metadata: AssetMetadata = {
  name: "Test Token",
  description: "This is a test nft",
  image: "ipfs://",
  mediaType: "image/jpg",
};

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

const myUTxOs = await wallet.getUtxos();
tx.setCollateral(myUTxOs);

tx.mintAsset(script, asset, redeemer);

const unsignedTx = await tx.build();
const signedTx = await wallet.signTx(unsignedTx);
const txHash = await wallet.submitTx(signedTx);

return txHash;

The issue is that it mints the NFT, but doesn't run the validations. Although in transaction, it shows that contract is executed, but even if I return false from script, it still gets minted.
export const mintNFT = pfn(
  [datum.type, redeemer.type, PScriptContext.type],
  bool
)((datum, message, ctx) => {
  return pBool(false);
});

Can someone please explain how can I resolve this issue?

**Tags:** minting, mesh, mintingpolicy, plu-ts

---

## 1 answers

### Answer by username_1 on 2024-01-05. Score: 0

I hope this answer doesn't come too late.
the problem is that you are trying to use a contract meant to validate a spending of an utxo for minting instead.
when used for minting you DO NOT need a datum.
datums are only used for spending scripts.
what happens here is that the node only passes 2 arguments to the script.
which implies the script is only partially applied; hence it returns a new function, without never throwing an error.
not throwing an error causes the node to think the contract agreed to the transaction, and proceeded.
the fix is easy.
you just want to remove the datum from the contract definition.
so your contract would look like this:
export const mintNFT = pfn(
  [redeemer.type, PScriptContext.type],
  bool
)((message, ctx) => {
  return pBool(false);
});


---

