0

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<TxHash> {
  const dtm: Datum = Data.to<VestingDatum>(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.

2 Answers 2

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

12
  • thanks, but even then all it tells me is "Redeemer (Spend, 0): end of input bytes" Apr 10, 2023 at 20:47
  • @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
    Apr 10, 2023 at 21:23
  • yes, the console.log at the beginning of the if always shows the right UTxO Apr 10, 2023 at 21:32
  • 1
    @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
    Apr 11, 2023 at 12:45
  • 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! Apr 11, 2023 at 19:32
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……"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.