<p>Instead of using a time-locked script, I required the user to include their wallet key as a witness.</p>
<p>Solution:</p>
<pre><code>
export async function mint(mintData: MintData, wasm: any, walletConnector: WalletConnector){
    const userAddress: Address = mintData.address.to_address()
    const netId: NetworkID = await walletConnector.getNetworkId()
    const p = initTxStatic(netId) 
  
    const txBuilder: TransactionBuilder = wasm.TransactionBuilder.new(
      wasm.TransactionBuilderConfigBuilder.new()
        .fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str(p.linearFee.minFeeA),
                                    wasm.BigNum.from_str(p.linearFee.minFeeB)))
        .pool_deposit(wasm.BigNum.from_str(p.poolDeposit))
        .key_deposit(wasm.BigNum.from_str(p.keyDeposit))
        .coins_per_utxo_word(wasm.BigNum.from_str(p.coinsPerUtxoWord))
        .max_value_size(p.maxValSize)
        .max_tx_size(p.maxTxSize)
        .build()
    );
    
    const baseAddress: BaseAddress = wasm.BaseAddress.from_address(userAddress)
    const scriptPubKey = wasm.ScriptPubkey.new(baseAddress.payment_cred().to_keyhash())
    const pubKeyScript = wasm.NativeScript.new_script_pubkey(scriptPubKey)
    const policyScripts = wasm.NativeScripts.new()
    policyScripts.add(pubKeyScript)
  
    const hexString = Util.hexEncode(mintData.assetName)
    const assetName: Uint8Array = Uint8Array.from(Buffer.from(hexString, 'hex'));
    txBuilder.add_mint_asset_and_output_min_required_coin(
      pubKeyScript, 
      wasm.AssetName.new(assetName), 
      wasm.Int.new_i32(mintData.amount),
      userAddress,
      );
    
  
    const valueFilter: Value = wasm.Value.new(wasm.BigNum.from_str(&quot;5000000&quot;)) 
    //Add inputs
    const utxos: TransactionUnspentOutputs = wasm.TransactionUnspentOutputs.new();
    const outputs: TransactionUnspentOutput[]  = (await walletConnector.getUtxos(valueFilter))
    outputs.forEach(utxo =&gt; utxos.add(utxo))
  
    
    txBuilder.add_inputs_from(utxos, 0)
  
    txBuilder.add_change_if_needed(userAddress)
    
    const toBeSignedTx: Transaction = txBuilder.build_tx();
  
    const witnessSet: TransactionWitnessSet = await walletConnector.signTx(toBeSignedTx)
  
    witnessSet.set_native_scripts(policyScripts)
  
    const submitTx: Transaction = 
      wasm.Transaction.new(
        toBeSignedTx.body(),
        witnessSet,
        undefined
      )
    await walletConnector.submitTx(submitTx)
  
  }
</code></pre>

CC BY-SA 4.0
2021-12-16T10:54:27.767Z
2021-12-16T10:54:27.767Z
Frank Weslien
<p>This error indicates you have all the witnesses you need for the transaction except the minting script and the policy key witness for minting.</p>
<p>You should be able to add a witnessSet to the transaction containing the missing policy script and policy key witness(es) before submitting.</p>

CC BY-SA 4.0
2021-12-14T14:36:52.483Z
2021-12-14T14:36:52.483Z
Samuel Leathers
<p>I'm trying to mint a native asset reusing the keys that Nami already uses. This is to make a minting service that is connected to a specific wallet, and that wallet is always able to mint more tokens if they want to.</p>
<p>However, it doesn't seem like Nami is providing all the signatures that I need. When submitting the transaction I get the following error:</p>
<pre><code>transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash \&quot;9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\&quot;]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoRedeemer (Minting (PolicyID {policyID = ScriptHash \&quot;9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\&quot;})),NoWitness (ScriptHash \&quot;9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\&quot;)]))))])
</code></pre>
<p>I seem to be missing the witness for the native asset script. Is there any way of making Nami sign this or is it impossible? Note that I'm already using the <code>signTx(...)</code> endpoint so it seems to be signing the entire transaction just not what is required by the minting script.</p>
<p><strong>Code:</strong></p>
<pre><code>async function mint(mintData: MintData, wasm: any, walletConnector: WalletConnector){
  const userAddress: Address = wasm.Address.from_bytes(
    Buffer.from(mintData.address, &quot;hex&quot;)
  )
  
  const p = await initTx() 

  const txBuilder: TransactionBuilder = wasm.TransactionBuilder.new(
    wasm.TransactionBuilderConfigBuilder.new()
      .fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str(p.linearFee.minFeeA),
                                  wasm.BigNum.from_str(p.linearFee.minFeeB)))
      .pool_deposit(wasm.BigNum.from_str(p.poolDeposit))
      .key_deposit(wasm.BigNum.from_str(p.keyDeposit))
      .coins_per_utxo_word(wasm.BigNum.from_str(p.coinsPerUtxoWord))
      .max_value_size(p.maxValSize)
      .max_tx_size(p.maxTxSize)
      .build()
  );
  
  const invalidHereafter=10

  if (p.slot === null){
    return
  }

  const ttl = p.slot+invalidHereafter
  const timelockExpiry = wasm.TimelockExpiry.new(ttl)
  const timeLockedPolicyScript = wasm.NativeScript.new_timelock_expiry(timelockExpiry)
  const policyScripts = wasm.NativeScripts.new()
  policyScripts.add(timeLockedPolicyScript)
  const scriptHash = wasm.ScriptHash.from_bytes(timeLockedPolicyScript.hash().to_bytes())
  const policyID = bytesToString(timeLockedPolicyScript.hash().to_bytes())

  //const assetName = Buffer.from(mintData.tokenName, 'hex')
  txBuilder.add_mint_asset_and_output_min_required_coin(
    timeLockedPolicyScript, 
    wasm.AssetName.new(mintData.tokenName), 
    wasm.Int.new_i32(mintData.amount),
    userAddress,
    );
  

  const valueFilter: Value = wasm.Value.new(wasm.BigNum.from_str(&quot;5000000&quot;)) 
  //Add inputs
  const utxos: TransactionUnspentOutputs = wasm.TransactionUnspentOutputs.new();
  (await walletConnector.getUtxos(Buffer.from(valueFilter.to_bytes()).toString('hex')))
                .forEach(rawUTXO =&gt; {
                  const utxo: TransactionUnspentOutput = wasm.TransactionUnspentOutput.from_bytes(Buffer.from(rawUTXO, &quot;hex&quot;))
                  utxos.add(utxo)
                })

  
  txBuilder.add_inputs_from(utxos, 0)

  txBuilder.add_change_if_needed(userAddress)
  
  const toBeSignedTx: Transaction = txBuilder.build_tx();
  const rawToBeSignedTx: string = Buffer.from(toBeSignedTx.to_bytes()).toString('hex')

  const rawWitnesses: string = await walletConnector.signTx(rawToBeSignedTx)
  const witnessSet = wasm.TransactionWitnessSet.from_bytes(
    Buffer.from(rawWitnesses, &quot;hex&quot;)
  )
  const witnessSets: TransactionWitnessSets = wasm.TransactionWitnessSets.new()
  witnessSets.add(witnessSet)

  const submitTx: Transaction = 
    wasm.Transaction.new(
      toBeSignedTx.body(),
      witnessSet
    )
  const rawSubmitTx: string = Buffer.from(submitTx.to_bytes()).toString('hex')
  walletConnector.submitTx(rawSubmitTx) // &lt;- Error occurs when submitting

}
</code></pre>

CC BY-SA 4.0
2021-12-11T10:59:20.263Z
lol I probably need to use `signData(...)` I'll update the post if that turns out to be the solution
Frank Weslien
CC BY-SA 4.0
2021-12-14T14:51:27.893Z
Where are you running it? is it Ts ? what is this walletConnector objet?
Alicia Basilio
CC BY-SA 4.0
2021-12-14T15:02:38.390Z
Yes it is possible, i am doing it with out any problems. So the problem must be somewhere in your code. As far as i see you are signing correctly. And you are not adding addressKeyHash in the policy, so there might be a problem related to other utxo? how are you getting the utxos? ...  Can you send a simpler Tx, with out minting?
Alicia Basilio
<native-assets><minting><nami>
Can Nami wallet provide the TransactionWitnessSet for minting a native asset?
# Can Nami wallet provide the TransactionWitnessSet for minting a native asset?

(Asked by: username_0 on 2021-12-11)

I'm trying to mint a native asset reusing the keys that Nami already uses. This is to make a minting service that is connected to a specific wallet, and that wallet is always able to mint more tokens if they want to.

However, it doesn't seem like Nami is providing all the signatures that I need. When submitting the transaction I get the following error:

```
transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoRedeemer (Minting (PolicyID {policyID = ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\"})),NoWitness (ScriptHash \"9f84ae8b52e374a0cd09e7ec10854309f8dd7b1f5caf69dd658ed6c5\")]))))])

```

I seem to be missing the witness for the native asset script. Is there any way of making Nami sign this or is it impossible? Note that I'm already using the `signTx(...)` endpoint so it seems to be signing the entire transaction just not what is required by the minting script.

**Code:**

```
async function mint(mintData: MintData, wasm: any, walletConnector: WalletConnector){
  const userAddress: Address = wasm.Address.from_bytes(
    Buffer.from(mintData.address, "hex")
  )
  
  const p = await initTx() 

  const txBuilder: TransactionBuilder = wasm.TransactionBuilder.new(
    wasm.TransactionBuilderConfigBuilder.new()
      .fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str(p.linearFee.minFeeA),
                                  wasm.BigNum.from_str(p.linearFee.minFeeB)))
      .pool_deposit(wasm.BigNum.from_str(p.poolDeposit))
      .key_deposit(wasm.BigNum.from_str(p.keyDeposit))
      .coins_per_utxo_word(wasm.BigNum.from_str(p.coinsPerUtxoWord))
      .max_value_size(p.maxValSize)
      .max_tx_size(p.maxTxSize)
      .build()
  );
  
  const invalidHereafter=10

  if (p.slot === null){
    return
  }

  const ttl = p.slot+invalidHereafter
  const timelockExpiry = wasm.TimelockExpiry.new(ttl)
  const timeLockedPolicyScript = wasm.NativeScript.new_timelock_expiry(timelockExpiry)
  const policyScripts = wasm.NativeScripts.new()
  policyScripts.add(timeLockedPolicyScript)
  const scriptHash = wasm.ScriptHash.from_bytes(timeLockedPolicyScript.hash().to_bytes())
  const policyID = bytesToString(timeLockedPolicyScript.hash().to_bytes())

  //const assetName = Buffer.from(mintData.tokenName, 'hex')
  txBuilder.add_mint_asset_and_output_min_required_coin(
    timeLockedPolicyScript, 
    wasm.AssetName.new(mintData.tokenName), 
    wasm.Int.new_i32(mintData.amount),
    userAddress,
    );
  

  const valueFilter: Value = wasm.Value.new(wasm.BigNum.from_str("5000000")) 
  //Add inputs
  const utxos: TransactionUnspentOutputs = wasm.TransactionUnspentOutputs.new();
  (await walletConnector.getUtxos(Buffer.from(valueFilter.to_bytes()).toString('hex')))
                .forEach(rawUTXO => {
                  const utxo: TransactionUnspentOutput = wasm.TransactionUnspentOutput.from_bytes(Buffer.from(rawUTXO, "hex"))
                  utxos.add(utxo)
                })

  
  txBuilder.add_inputs_from(utxos, 0)

  txBuilder.add_change_if_needed(userAddress)
  
  const toBeSignedTx: Transaction = txBuilder.build_tx();
  const rawToBeSignedTx: string = Buffer.from(toBeSignedTx.to_bytes()).toString('hex')

  const rawWitnesses: string = await walletConnector.signTx(rawToBeSignedTx)
  const witnessSet = wasm.TransactionWitnessSet.from_bytes(
    Buffer.from(rawWitnesses, "hex")
  )
  const witnessSets: TransactionWitnessSets = wasm.TransactionWitnessSets.new()
  witnessSets.add(witnessSet)

  const submitTx: Transaction = 
    wasm.Transaction.new(
      toBeSignedTx.body(),
      witnessSet
    )
  const rawSubmitTx: string = Buffer.from(submitTx.to_bytes()).toString('hex')
  walletConnector.submitTx(rawSubmitTx) // <- Error occurs when submitting

}

```

**Tags:** native-assets, minting, nami

> **Comments:**
> **username_0**: lol I probably need to use `signData(...)` I'll update the post if that turns out to be the solution  
> **username_1**: Where are you running it? is it Ts ? what is this walletConnector objet?  
> **username_1**: Yes it is possible, i am doing it with out any problems. So the problem must be somewhere in your code. As far as i see you are signing correctly. And you are not adding addressKeyHash in the policy, so there might be a problem related to other utxo? how are you getting the utxos? ...  Can you send a simpler Tx, with out minting?  

---

## 2 answers

### Answer by username_0 on 2021-12-16. Score: 0 | Accepted answer

Instead of using a time-locked script, I required the user to include their wallet key as a witness.

Solution:

```

export async function mint(mintData: MintData, wasm: any, walletConnector: WalletConnector){
    const userAddress: Address = mintData.address.to_address()
    const netId: NetworkID = await walletConnector.getNetworkId()
    const p = initTxStatic(netId) 
  
    const txBuilder: TransactionBuilder = wasm.TransactionBuilder.new(
      wasm.TransactionBuilderConfigBuilder.new()
        .fee_algo(wasm.LinearFee.new(wasm.BigNum.from_str(p.linearFee.minFeeA),
                                    wasm.BigNum.from_str(p.linearFee.minFeeB)))
        .pool_deposit(wasm.BigNum.from_str(p.poolDeposit))
        .key_deposit(wasm.BigNum.from_str(p.keyDeposit))
        .coins_per_utxo_word(wasm.BigNum.from_str(p.coinsPerUtxoWord))
        .max_value_size(p.maxValSize)
        .max_tx_size(p.maxTxSize)
        .build()
    );
    
    const baseAddress: BaseAddress = wasm.BaseAddress.from_address(userAddress)
    const scriptPubKey = wasm.ScriptPubkey.new(baseAddress.payment_cred().to_keyhash())
    const pubKeyScript = wasm.NativeScript.new_script_pubkey(scriptPubKey)
    const policyScripts = wasm.NativeScripts.new()
    policyScripts.add(pubKeyScript)
  
    const hexString = Util.hexEncode(mintData.assetName)
    const assetName: Uint8Array = Uint8Array.from(Buffer.from(hexString, 'hex'));
    txBuilder.add_mint_asset_and_output_min_required_coin(
      pubKeyScript, 
      wasm.AssetName.new(assetName), 
      wasm.Int.new_i32(mintData.amount),
      userAddress,
      );
    
  
    const valueFilter: Value = wasm.Value.new(wasm.BigNum.from_str("5000000")) 
    //Add inputs
    const utxos: TransactionUnspentOutputs = wasm.TransactionUnspentOutputs.new();
    const outputs: TransactionUnspentOutput[]  = (await walletConnector.getUtxos(valueFilter))
    outputs.forEach(utxo => utxos.add(utxo))
  
    
    txBuilder.add_inputs_from(utxos, 0)
  
    txBuilder.add_change_if_needed(userAddress)
    
    const toBeSignedTx: Transaction = txBuilder.build_tx();
  
    const witnessSet: TransactionWitnessSet = await walletConnector.signTx(toBeSignedTx)
  
    witnessSet.set_native_scripts(policyScripts)
  
    const submitTx: Transaction = 
      wasm.Transaction.new(
        toBeSignedTx.body(),
        witnessSet,
        undefined
      )
    await walletConnector.submitTx(submitTx)
  
  }

```


---

### Answer by username_2 on 2021-12-14. Score: 0

This error indicates you have all the witnesses you need for the transaction except the minting script and the policy key witness for minting.

You should be able to add a witnessSet to the transaction containing the missing policy script and policy key witness(es) before submitting.


---

