<p>Review your <code>vestingScript</code> in Lucid. It's supposed to be structured as follows:</p>
<pre><code>const vestingScript: SpendingValidator = {
    type: &quot;PlutusV2&quot;,
    script: &quot;590b30590b2d010000323……”,
};
</code></pre>
<p>However, after compiling, the JSON output is formatted differently:</p>
<pre><code>{
    &quot;type&quot;: &quot;PlutusScriptV2&quot;,
    &quot;description&quot;: &quot;&quot;,
    &quot;cborHex&quot;: &quot;590b30590b2d010000323……&quot;
}
</code></pre>

CC BY-SA 4.0
2023-11-14T15:53:33.787Z
2023-11-14T15:53:33.787Z
rushmore
<p>Quoted from the answer linked below:</p>
<p>The error tells you that there is an error but you don't catch it. This is how you can catch it:</p>
<pre><code>claimVestedFunds().then(response =&gt; {
    console.log(response);
}).catch(e =&gt; {
    console.log(e);
});
</code></pre>
<p><a href="https://stackoverflow.com/questions/37624322/uncaught-in-promise-undefined-error-when-using-with-location-in-facebook-gra">https://stackoverflow.com/questions/37624322/uncaught-in-promise-undefined-error-when-using-with-location-in-facebook-gra</a></p>

CC BY-SA 4.0
2023-04-10T20:47:26.477Z
thanks, but even then all it tells me is "Redeemer (Spend, 0): end of input bytes"
user3755529
CC BY-SA 4.0
2023-04-10T21:23:04.877Z
@user3755529 I wonder if it's possible your line for filtering is not working? This line ```const ourUTxO: UTxO[] = utxoAtScript.filter((utxo) => utxo.datum == dtm);``` Are you getting a valid utxo every time?
PREEB
CC BY-SA 4.0
2023-04-10T21:32:22.283Z
yes, the `console.log` at the beginning of the `if` always shows the right UTxO
user3755529
CC BY-SA 4.0
2023-04-11T12:45:06.523Z
@user3755529 Can you try a couple things? Preferably 1 at a time to narrow it down. 1. Instead of passing Data.void() into collectFrom, set a const and pass it in like follows ```const Redeemer = () => Data.void();```
2. You are calling complete() twice on the same tx. I'm guessing you just need to do this once. 
3. I would also try not passing Data.void() at all, since it's supposed to be optional. It looks like the lucid code checks if it's undefined, so really it should work without passing anything.
PREEB
CC BY-SA 4.0
2023-04-11T19:32:25.250Z
oh wow, yes, that seem to work, I get another error after at submit stage, need to look on it, but it seem the previous error is gone and I pass validation, thanks!
user3755529
CC BY-SA 4.0
2023-04-11T23:25:56.553Z
although now when I use `const Redeemer = () => Data.void();` it tells me `encoding/hex: invalid byte: (return new Error(..` and when I put nothing the transaction fails saying it lacks a redeemer `.. (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (MissingRedeemers ..`
user3755529
CC BY-SA 4.0
2023-04-12T15:59:46.043Z
@user3755529 Can you post the entire error for the invalid byte issue? Might be a red herring tho. The `complete()` call should come directly after the `sign()` call. I should have mentioned that before when I said you only needed one. Sadly Lucid's docs are sparse. I would also try it without validFrom. In its entirety ```
const Redeemer = () => Data.void();
const tx = await lucid
          .newTx()
          .collectFrom(ourUTxO, Redeemer)
          .addSignerKey(beneficiaryPKH)
          .attachSpendingValidator(vestingScript);

      const signedTx = await tx.sign().complete();```
PREEB
CC BY-SA 4.0
2023-04-13T17:08:17.277Z
if I don't use complete in the first variable tx I get `TypeError: tx.sign is not a function
      const signedTx = await tx.sign().complete()`
user3755529
CC BY-SA 4.0
2023-04-13T17:11:41.953Z
error: Uncaught (in promise) Error: encoding/hex: invalid byte: (
  return new Error(
         ^
    at errInvalidByte (https://deno.land/std@0.100.0/encoding/hex.ts:15:10)
    at fromHexChar (https://deno.land/std@0.100.0/encoding/hex.ts:35:9)
    at decode (https://deno.land/std@0.100.0/encoding/hex.ts:78:15)
    at decodeString (https://deno.land/std@0.100.0/encoding/hex.ts:110:10)
    at fromHex (https://deno.land/x/lucid@0.9.1/src/utils/utils.ts:577:10)
user3755529
CC BY-SA 4.0
2023-04-13T17:11:48.347Z
at https://deno.land/x/lucid@0.9.1/src/lucid/tx.ts:80:41
    at Tx.complete (https://deno.land/x/lucid@0.9.1/src/lucid/tx.ts:534:13)
    at claimVestedFunds (file:///workspace/code/Week04/lecture/homework1.ts:97:34)
    at async file:///workspace/code/Week04/lecture/homework1.ts:112:13
user3755529
CC BY-SA 4.0
2023-04-13T18:57:49.337Z
@user3755529 Looks like the line above this error is missing. The carat `^` is pointing to the actual char thats bad. Is there a line above this error that you can paste here. 
`Error: encoding/hex: invalid byte: ( return new Error( ^ at errInvalidByte`
Maybe try changing the collectFrom to this. 
`.collectFrom([ourUTxO], Redeemer)`
PREEB
CC BY-SA 4.0
2023-04-13T19:37:50.050Z
the `^` is pointing at `n`  in `new Error`
user3755529
CC BY-SA 4.0
2023-04-10T19:33:45.623Z
2023-04-10T19:33:45.623Z
PREEB
<p>I am running the simple vesting script from PPP for the first time with Lucid and I continuosly get an error which doesn't give me much to understand what could realistically be the source of.</p>
<p>the validator goes:</p>
<pre class="lang-haskell prettyprint-override"><code>data MisteryDatum = MisteryDatum
    { beneficiary1 :: PubKeyHash
    , beneficiary2 :: PubKeyHash
    , deadline     :: POSIXTime
    }

unstableMakeIsData ''MisteryDatum

{-# INLINABLE mkMisteryValidator #-}
mkMisteryValidator :: MisteryDatum -&gt; () -&gt; ScriptContext -&gt; Bool
mkMisteryValidator dat () ctx =
    traceIfFalse &quot;Benificiary1 did not sign or to late&quot; checkCondition1 ||
    traceIfFalse &quot;Benificiary2 did not sign or is to early&quot; checkCondition2
    where
        txInfo :: TxInfo
        txInfo = scriptContextTxInfo ctx

        txValidRange :: POSIXTimeRange
        txValidRange  = txInfoValidRange txInfo

        checkCondition1 :: Bool
        checkCondition1 = txSignedBy txInfo (beneficiary1 dat) &amp;&amp;
                          contains (to (deadline dat)) txValidRange

        checkCondition2 :: Bool
        checkCondition2 = txSignedBy txInfo (beneficiary2 dat) &amp;&amp;
                          contains (from (1 + deadline dat)) txValidRange
</code></pre>
<p>while the Lucid function that causes the error is:</p>
<pre class="lang-js prettyprint-override"><code>async function claimVestedFunds(): Promise&lt;TxHash&gt; {
  const dtm: Datum = Data.to&lt;VestingDatum&gt;(datum,VestingDatum);
  const utxoAtScript: UTxO[] = await lucid.utxosAt(vestingAddress);
  const ourUTxO: UTxO[] = utxoAtScript.filter((utxo) =&gt; utxo.datum == dtm);
  
  if (ourUTxO &amp;&amp; ourUTxO.length &gt; 0) {
      console.log(ourUTxO)
      const tx = await lucid
          .newTx()
          .collectFrom(ourUTxO, Data.void())
          .addSignerKey(beneficiaryPKH)
          .attachSpendingValidator(vestingScript)
          .validFrom(Date.now())
          .complete();

      const signedTx = await tx.sign().complete();
      const txHash = await signedTx.submit();
      return txHash
  }
  else return &quot;No UTxO's found that can be claimed&quot;
}
</code></pre>
<p>I checked date and beneficiary many times and they are correct, the only problem could be that I am using the same address public key for both benificiary1 and benificiary2. But that shouldn't be a problem right?</p>
<p>Anyway the function above shows the right UTxO</p>
<pre class="lang-json prettyprint-override"><code>[
  {
    txHash: &quot;a1d743f6a6c795dff9a5691ee25f1831485dd59f57476d6d9260691aaf65c3e6&quot;,
    outputIndex: 0,
    assets: { lovelace: 8700000n },
    address: &quot;addr_test1wznyv36t3a2rzfs4q6mvyu7nqlr4dxjwkmykkskafg54yzs735734&quot;,
    datumHash: undefined,
    datum: &quot;d8799f581ccecc6981a300d41fac6ae169c569a297c2837b1d8988762034ba4a65581ccecc6981a300d41fac6ae169c569a2...&quot;,
    scriptRef: null
  }
]
</code></pre>
<p>At this point something in the validation fails before the transaction is even sent and I receive the followign error:</p>
<pre class="lang-bash prettyprint-override"><code>error: Uncaught (in promise) &quot;Redeemer (Spend, 0): end of input bytes&quot;
</code></pre>
<p>I don't understand what could cause it as everything seem right and the error isn't articulated enough to give me precise indications, but what seem to cause that error is the line <code>.collectFrom(ourUTxO, Data.void())</code> which seem fine to me as the UTxO is the right UTxO and the redeemer has to be void.</p>

<validator><validation><offchain><lucid>
Lucid Error "End of input in bytes"
# Lucid Error "End of input in bytes"

(Asked by: username_0 on 2023-04-10)

I am running the simple vesting script from PPP for the first time with Lucid and I continuosly get an error which doesn't give me much to understand what could realistically be the source of.
the validator goes:
data MisteryDatum = MisteryDatum
    { beneficiary1 :: PubKeyHash
    , beneficiary2 :: PubKeyHash
    , deadline     :: POSIXTime
    }

unstableMakeIsData ''MisteryDatum

{-# INLINABLE mkMisteryValidator #-}
mkMisteryValidator :: MisteryDatum -> () -> ScriptContext -> Bool
mkMisteryValidator dat () ctx =
    traceIfFalse "Benificiary1 did not sign or to late" checkCondition1 ||
    traceIfFalse "Benificiary2 did not sign or is to early" checkCondition2
    where
        txInfo :: TxInfo
        txInfo = scriptContextTxInfo ctx

        txValidRange :: POSIXTimeRange
        txValidRange  = txInfoValidRange txInfo

        checkCondition1 :: Bool
        checkCondition1 = txSignedBy txInfo (beneficiary1 dat) &&
                          contains (to (deadline dat)) txValidRange

        checkCondition2 :: Bool
        checkCondition2 = txSignedBy txInfo (beneficiary2 dat) &&
                          contains (from (1 + deadline dat)) txValidRange

while the Lucid function that causes the error is:
async function claimVestedFunds(): Promise {
  const dtm: Datum = Data.to(datum,VestingDatum);
  const utxoAtScript: UTxO[] = await lucid.utxosAt(vestingAddress);
  const ourUTxO: UTxO[] = utxoAtScript.filter((utxo) => utxo.datum == dtm);
  
  if (ourUTxO && ourUTxO.length > 0) {
      console.log(ourUTxO)
      const tx = await lucid
          .newTx()
          .collectFrom(ourUTxO, Data.void())
          .addSignerKey(beneficiaryPKH)
          .attachSpendingValidator(vestingScript)
          .validFrom(Date.now())
          .complete();

      const signedTx = await tx.sign().complete();
      const txHash = await signedTx.submit();
      return txHash
  }
  else return "No UTxO's found that can be claimed"
}

I checked date and beneficiary many times and they are correct, the only problem could be that I am using the same address public key for both benificiary1 and benificiary2. But that shouldn't be a problem right?
Anyway the function above shows the right UTxO
[
  {
    txHash: "a1d743f6a6c795dff9a5691ee25f1831485dd59f57476d6d9260691aaf65c3e6",
    outputIndex: 0,
    assets: { lovelace: 8700000n },
    address: "addr_test1wznyv36t3a2rzfs4q6mvyu7nqlr4dxjwkmykkskafg54yzs735734",
    datumHash: undefined,
    datum: "d8799f581ccecc6981a300d41fac6ae169c569a297c2837b1d8988762034ba4a65581ccecc6981a300d41fac6ae169c569a2...",
    scriptRef: null
  }
]

At this point something in the validation fails before the transaction is even sent and I receive the followign error:
error: Uncaught (in promise) "Redeemer (Spend, 0): end of input bytes"

I don't understand what could cause it as everything seem right and the error isn't articulated enough to give me precise indications, but what seem to cause that error is the line .collectFrom(ourUTxO, Data.void()) which seem fine to me as the UTxO is the right UTxO and the redeemer has to be void.

**Tags:** validator, validation, offchain, lucid

---

## 2 answers

### Answer by username_1 on 2023-11-14. Score: 0

Review your vestingScript in Lucid. It's supposed to be structured as follows:
const vestingScript: SpendingValidator = {
    type: "PlutusV2",
    script: "590b30590b2d010000323……”,
};

However, after compiling, the JSON output is formatted differently:
{
    "type": "PlutusScriptV2",
    "description": "",
    "cborHex": "590b30590b2d010000323……"
}


---

### Answer by username_2 on 2023-04-10. Score: 0

Quoted from the answer linked below:
The error tells you that there is an error but you don't catch it. This is how you can catch it:
claimVestedFunds().then(response => {
    console.log(response);
}).catch(e => {
    console.log(e);
});

https://stackoverflow.com/questions/37624322/uncaught-in-promise-undefined-error-when-using-with-location-in-facebook-gra

> **Comments:**
> **username_0**: thanks, but even then all it tells me is "Redeemer (Spend, 0): end of input bytes"  
> **username_2**: @user3755529 I wonder if it's possible your line for filtering is not working? This line ```const ourUTxO: UTxO[] = utxoAtScript.filter((utxo) => utxo.datum == dtm);``` Are you getting a valid utxo every time?  
> **username_0**: yes, the `console.log` at the beginning of the `if` always shows the right UTxO  
> **username_2**: @user3755529 Can you try a couple things? Preferably 1 at a time to narrow it down. 1. Instead of passing Data.void() into collectFrom, set a const and pass it in like follows ```const Redeemer = () => Data.void();``` 2. You are calling complete() twice on the same tx. I'm guessing you just need to do this once.  3. I would also try not passing Data.void() at all, since it's supposed to be optional. It looks like the lucid code checks if it's undefined, so really it should work without passing anything.  
> **username_0**: oh wow, yes, that seem to work, I get another error after at submit stage, need to look on it, but it seem the previous error is gone and I pass validation, thanks!  
> **username_0**: although now when I use `const Redeemer = () => Data.void();` it tells me `encoding/hex: invalid byte: (return new Error(..` and when I put nothing the transaction fails saying it lacks a redeemer `.. (ApplyTxError [UtxowFailure (FromAlonzoUtxowFail (MissingRedeemers ..`  
> **username_2**: @user3755529 Can you post the entire error for the invalid byte issue? Might be a red herring tho. The `complete()` call should come directly after the `sign()` call. I should have mentioned that before when I said you only needed one. Sadly Lucid's docs are sparse. I would also try it without validFrom. In its entirety ``` const Redeemer = () => Data.void(); const tx = await lucid           .newTx()           .collectFrom(ourUTxO, Redeemer)           .addSignerKey(beneficiaryPKH)           .attachSpendingValidator(vestingScript);        const signedTx = await tx.sign().complete();```  
> **username_0**: if I don't use complete in the first variable tx I get `TypeError: tx.sign is not a function       const signedTx = await tx.sign().complete()`  
> **username_0**: error: Uncaught (in promise) Error: encoding/hex: invalid byte: (   return new Error(          ^     at errInvalidByte (https://deno.land/std@0.100.0/encoding/hex.ts:15:10)     at fromHexChar (https://deno.land/std@0.100.0/encoding/hex.ts:35:9)     at decode (https://deno.land/std@0.100.0/encoding/hex.ts:78:15)     at decodeString (https://deno.land/std@0.100.0/encoding/hex.ts:110:10)     at fromHex (https://deno.land/x/lucid@0.9.1/src/utils/utils.ts:577:10)  
> **username_0**: at https://deno.land/x/lucid@0.9.1/src/lucid/tx.ts:80:41     at Tx.complete (https://deno.land/x/lucid@0.9.1/src/lucid/tx.ts:534:13)     at claimVestedFunds (file:///workspace/code/Week04/lecture/homework1.ts:97:34)     at async file:///workspace/code/Week04/lecture/homework1.ts:112:13  
> **username_2**: @user3755529 Looks like the line above this error is missing. The carat `^` is pointing to the actual char thats bad. Is there a line above this error that you can paste here.  `Error: encoding/hex: invalid byte: ( return new Error( ^ at errInvalidByte` Maybe try changing the collectFrom to this.  `.collectFrom([ourUTxO], Redeemer)`  
> **username_0**: the `^` is pointing at `n`  in `new Error`  

---

