<p>There was a bug in the CSL lib for consuming multiple script outputs in one transaction which was resolved by <a href="https://github.com/Emurgo/cardano-serialization-lib/issues/536" rel="nofollow noreferrer">https://github.com/Emurgo/cardano-serialization-lib/issues/536</a></p>

CC BY-SA 4.0
2022-11-24T07:44:26.020Z
2022-11-24T07:44:26.020Z
Will
<p>I am getting the following error, when I try to submit a transaction that spends 2 script outputs:</p>
<pre><code>Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (MissingRedeemers [(Spending (TxIn (TxId {_unTxId = SafeHash &quot;23e874d6549250c6d845031974212f87edb7f1b1d0f676afdf03cbddaf0ae9ad&quot;}) (TxIx 0)),ScriptHash &quot;d8feffeeee5fe079055719280d2a9603d93dc1289c2dff9912378d51&quot;)])),UtxowFailure (FromAlonzoUtxowFail (PPViewHashesDontMatch (SJust (SafeHash &quot;0b672c4621917cc5ff6a62770cbd2841fa419603c43bb0d19d09b45ec184f995&quot;)) (SJust (SafeHash &quot;72efce08bafc21afb779a47940e1866b53b4d33da32bc052f15ce80b2e49f5ce&quot;)))),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (UtxosFailure (CollectErrors [NoRedeemer (Spending (TxIn (TxId {_unTxId = SafeHash &quot;23e874d6549250c6d845031974212f87edb7f1b1d0f676afdf03cbddaf0ae9ad&quot;}) (TxIx 0)))]))))])
</code></pre>
<p>I am currently using the following code to create the Tx inputs:</p>
<pre><code>for (let i = 0; i &lt; sortedScriptTxInputs.length; i++) {
    const o = sortedScriptTxInputs[i];
    const txIn = TransactionInput.new(TransactionHash.from_bytes(Buffer.from(o.txId, 'hex')), o.idx);
    const redeemer = Redeemer.new(
      RedeemerTag.new_spend(),
      BigNum.from_str(`${i}`),     // NOT SURE IF THIS IS THE RIGHT WAY TO INDEX REDEEMERS ?!
      PlutusData.new_empty_constr_plutus_data(BigNum.zero()),
      ExUnits.new(
        BigNum.from_str(&quot;7000000&quot;),
        BigNum.from_str(&quot;5000000000&quot;)
      )
    );
    const plutusWitness = PlutusWitness.new_with_ref(PlutusScriptSource.new(spendingContract), DatumSource.new_ref_input(txIn), redeemer);
    const amt = Value.new(BigNum.from_str(`${o.value.coins}`));
    txBuilder.add_plutus_script_input(plutusWitness, txIn, amt);
}
</code></pre>
<p>After adding collateral, I am creating the respective plutus-v2 CostModel and add it like so:</p>
<pre><code>const costModel = TxBuilderConstants.plutus_vasil_cost_models().get(Language.new_plutus_v2());
if (!costModel)
    throw new Error('Missing cost model');
const costModels = Costmdls.new();
costModels.insert(Language.new_plutus_v2(), costModel);
txBuilder.calc_script_data_hash(costModels);
</code></pre>
<p><strong>Observation:</strong></p>
<p>If I inspect the redeemer witness set after building the Tx, I would expect to see <strong>2 redeemers</strong> but the array only contains <strong>1</strong>.</p>
<pre><code>const tx = txBuilder.build_tx();
console.log('Witness Set before signing:');
console.log(tx.witness_set().redeemers()?.to_json());
</code></pre>
<p><strong>Output</strong></p>
<pre><code>Witness Set before signing:
[
  {
    &quot;tag&quot;: &quot;Spend&quot;,
    &quot;index&quot;: &quot;1&quot;,
    &quot;data&quot;: &quot;{\&quot;constructor\&quot;:0,\&quot;fields\&quot;:[]}&quot;,
    &quot;ex_units&quot;: {
      &quot;mem&quot;: &quot;7000000&quot;,
      &quot;steps&quot;: &quot;5000000000&quot;
    }
  }
]
</code></pre>
<p>What am I missing or constructing wrongly?
My suspicion is that I either create invalid indexed redeemers or that <code>txBuilder.calc_script_data_hash</code> or <code>txBuilder.build_tx</code> does not handle multiple redeemers correctly.</p>
<p>Thanks for any help!</p>

CC BY-SA 4.0
2022-10-11T20:42:12.303Z
Is interesting that `"index": "1"`; you should have at least a redeemer with index 0;not sure at this point if indexing starts from 1 but that would be weird; what is the output if you try `BigNum.from_str((i + 1).toString())`
Michele Nuzzi
CC BY-SA 4.0
2022-10-12T08:37:04.163Z
According to this post, I am using it correctly.
https://github.com/Emurgo/cardano-serialization-lib/issues/499#issuecomment-1217882349
Will
CC BY-SA 4.0
2022-10-13T08:31:48.573Z
It seems there is an issue with `txBuilder#calc_script_data_hash` as well as for `#build_tx` according to this thread:
https://github.com/Emurgo/cardano-serialization-lib/issues/536
Will
<plutus><redeemer><plutus-v2>
Missing/ No Redeemer Error when spending 2 script outputs
# Missing/ No Redeemer Error when spending 2 script outputs

(Asked by: username_0 on 2022-10-09)

I am getting the following error, when I try to submit a transaction that spends 2 script outputs:
Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (MissingRedeemers [(Spending (TxIn (TxId {_unTxId = SafeHash "23e874d6549250c6d845031974212f87edb7f1b1d0f676afdf03cbddaf0ae9ad"}) (TxIx 0)),ScriptHash "d8feffeeee5fe079055719280d2a9603d93dc1289c2dff9912378d51")])),UtxowFailure (FromAlonzoUtxowFail (PPViewHashesDontMatch (SJust (SafeHash "0b672c4621917cc5ff6a62770cbd2841fa419603c43bb0d19d09b45ec184f995")) (SJust (SafeHash "72efce08bafc21afb779a47940e1866b53b4d33da32bc052f15ce80b2e49f5ce")))),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (UtxosFailure (CollectErrors [NoRedeemer (Spending (TxIn (TxId {_unTxId = SafeHash "23e874d6549250c6d845031974212f87edb7f1b1d0f676afdf03cbddaf0ae9ad"}) (TxIx 0)))]))))])

I am currently using the following code to create the Tx inputs:
for (let i = 0; i < sortedScriptTxInputs.length; i++) {
    const o = sortedScriptTxInputs[i];
    const txIn = TransactionInput.new(TransactionHash.from_bytes(Buffer.from(o.txId, 'hex')), o.idx);
    const redeemer = Redeemer.new(
      RedeemerTag.new_spend(),
      BigNum.from_str(`${i}`),     // NOT SURE IF THIS IS THE RIGHT WAY TO INDEX REDEEMERS ?!
      PlutusData.new_empty_constr_plutus_data(BigNum.zero()),
      ExUnits.new(
        BigNum.from_str("7000000"),
        BigNum.from_str("5000000000")
      )
    );
    const plutusWitness = PlutusWitness.new_with_ref(PlutusScriptSource.new(spendingContract), DatumSource.new_ref_input(txIn), redeemer);
    const amt = Value.new(BigNum.from_str(`${o.value.coins}`));
    txBuilder.add_plutus_script_input(plutusWitness, txIn, amt);
}

After adding collateral, I am creating the respective plutus-v2 CostModel and add it like so:
const costModel = TxBuilderConstants.plutus_vasil_cost_models().get(Language.new_plutus_v2());
if (!costModel)
    throw new Error('Missing cost model');
const costModels = Costmdls.new();
costModels.insert(Language.new_plutus_v2(), costModel);
txBuilder.calc_script_data_hash(costModels);

Observation:
If I inspect the redeemer witness set after building the Tx, I would expect to see 2 redeemers but the array only contains 1.
const tx = txBuilder.build_tx();
console.log('Witness Set before signing:');
console.log(tx.witness_set().redeemers()?.to_json());

Output
Witness Set before signing:
[
  {
    "tag": "Spend",
    "index": "1",
    "data": "{\"constructor\":0,\"fields\":[]}",
    "ex_units": {
      "mem": "7000000",
      "steps": "5000000000"
    }
  }
]

What am I missing or constructing wrongly?
My suspicion is that I either create invalid indexed redeemers or that txBuilder.calc_script_data_hash or txBuilder.build_tx does not handle multiple redeemers correctly.
Thanks for any help!

**Tags:** plutus, redeemer, plutus-v2
> **Comments:**
> **username_1**: Is interesting that `"index": "1"`; you should have at least a redeemer with index 0;not sure at this point if indexing starts from 1 but that would be weird; what is the output if you try `BigNum.from_str((i + 1).toString())`  
> **username_0**: According to this post, I am using it correctly. https://github.com/Emurgo/cardano-serialization-lib/issues/499#issuecomment-1217882349  
> **username_0**: It seems there is an issue with `txBuilder#calc_script_data_hash` as well as for `#build_tx` according to this thread: https://github.com/Emurgo/cardano-serialization-lib/issues/536  

---

## 1 answers

### Answer by username_0 on 2022-11-24. Score: 0 | Accepted answer

There was a bug in the CSL lib for consuming multiple script outputs in one transaction which was resolved by <https://github.com/Emurgo/cardano-serialization-lib/issues/536>


---

