<p>The error occurs because you are not explicitly providing the private key (<code>.skey</code>) needed to sign the transaction under the existing policy. Without this key, the signing process fails.</p>
<p><strong>Error</strong></p>
<ul>
<li><strong>Cause</strong>: Calling <code>.sign()</code> without the private key for the policy.</li>
<li><strong>Solution</strong>: Load the <code>.skey</code> file and use <code>signWithPrivateKey</code> to sign the transaction.</li>
</ul>
<p><strong>Fix</strong></p>
<p>Load the <code>.skey</code> file:</p>
<pre><code>const fs = require('fs');
const skey = JSON.parse(fs.readFileSync(&quot;path_to_user_provided_skey_file.skey&quot;, 'utf8'));
</code></pre>
<p><strong>Sign the transaction:</strong></p>
<pre><code>const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);
console.log(&quot;Policy ID: &quot;, policyId);

const unit = policyId + fromText(&quot;My NFT - &quot; + Date.now().toString());

const tx = await lucid
  .newTx()
  .mintAssets({ [unit]: BigInt(1) })
  .attachMintingPolicy(mintingPolicy)
  .complete();

const signedTx = await tx.signWithPrivateKey(skey.cborHex).complete();
</code></pre>
<p><strong>Why It Works</strong></p>
<p>The <code>.skey</code> file contains the private key (<code>cborHex</code>) required to sign and authorize transactions for the minting policy.
Using <code>signWithPrivateKey</code> ensures the transaction is properly signed and ready for submission.</p>

CC BY-SA 4.0
2024-12-16T23:01:47.113Z
2024-12-16T23:01:47.113Z
Dan Baruka
<p>I have an API endpoint that I use in my app to create cardano NFTs. This works fine when creating new policies but I'd like to let the user provide their policy script and skey file to mint on an existing policy.</p>
<p>The transaction fails to sign because I haven't provided the .skey file but I can't figure out where I'm supposed to do this.</p>
<pre><code>const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);
console.log(&quot;Policy ID: &quot;, policyId);

const unit = policyId + fromText(&quot;My NFT - &quot; + Date.now().toString());

const tx = await lucid
  .newTx()
  .mintAssets({ [unit]: BigInt(1) })
  .attachMintingPolicy(mintingPolicy)
  .complete();

const signedTx = await tx.sign().complete();
</code></pre>

<transaction><javascript><lucid><signing-key-file>
Unable to sign nft minting transaction using skey
# Unable to sign nft minting transaction using skey

(Asked by: username_0 on 2024-12-13)

I have an API endpoint that I use in my app to create cardano NFTs. This works fine when creating new policies but I'd like to let the user provide their policy script and skey file to mint on an existing policy.
The transaction fails to sign because I haven't provided the .skey file but I can't figure out where I'm supposed to do this.
const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);
console.log("Policy ID: ", policyId);

const unit = policyId + fromText("My NFT - " + Date.now().toString());

const tx = await lucid
  .newTx()
  .mintAssets({ [unit]: BigInt(1) })
  .attachMintingPolicy(mintingPolicy)
  .complete();

const signedTx = await tx.sign().complete();

**Tags:** transaction, javascript, lucid, signing-key-file

---

## 1 answers

### Answer by username_1 on 2024-12-16. Score: 0

The error occurs because you are not explicitly providing the private key (.skey) needed to sign the transaction under the existing policy. Without this key, the signing process fails.
Error

Cause: Calling .sign() without the private key for the policy.
Solution: Load the .skey file and use signWithPrivateKey to sign the transaction.

Fix
Load the .skey file:
const fs = require('fs');
const skey = JSON.parse(fs.readFileSync("path_to_user_provided_skey_file.skey", 'utf8'));

Sign the transaction:
const policyId = lucid.utils.mintingPolicyToId(mintingPolicy);
console.log("Policy ID: ", policyId);

const unit = policyId + fromText("My NFT - " + Date.now().toString());

const tx = await lucid
  .newTx()
  .mintAssets({ [unit]: BigInt(1) })
  .attachMintingPolicy(mintingPolicy)
  .complete();

const signedTx = await tx.signWithPrivateKey(skey.cborHex).complete();

Why It Works
The .skey file contains the private key (cborHex) required to sign and authorize transactions for the minting policy.
Using signWithPrivateKey ensures the transaction is properly signed and ready for submission.


---

