Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlock transaction: Uncaught (in promise) Redeemer (Spend, 0): Failed to deserialise PlutusData using UnConstrData: #244

Open
NicolasEliasArias opened this issue Feb 26, 2024 · 7 comments

Comments

@NicolasEliasArias
Copy link

NicolasEliasArias commented Feb 26, 2024

Hi! I'm creating a simple transaction to unlock some ada:

    const redeemer = Data.to(100n);

    const tx = await lucid
      .newTx()
      .collectFrom([utxo], redeemer)
      .addSigner(await lucid.wallet.address())
      .attachSpendingValidator(lucidValidator)
      .complete();

And I'm getting this error when .complete() is called:

Uncaught (in promise) Redeemer (Spend, 0): Failed to deserialise PlutusData using UnConstrData: ...

The problem is in the redeemer, I tested multiple ways to create different redeemers and I'm getting similar errors every time:

    const json = Data.fromJson({
       msg: "Hello, World!",
     });
    const redeemer = Data.to(json);
    const redeemer = Data.to(
      new Constr(0, [Buffer.from("Hello World", "utf8").toString("hex")]),
    );
    const redeemer = Data.to(
      new Constr(0, [toHex(Buffer.from("Hello World", "utf8"))]),
    );
    const redeemer = Data.void()
@NicolasEliasArias NicolasEliasArias changed the title Unlock trnasaction: Uncaught (in promise) Redeemer (Spend, 0): Failed to deserialise PlutusData using UnConstrData: Unlock transaction: Uncaught (in promise) Redeemer (Spend, 0): Failed to deserialise PlutusData using UnConstrData: Feb 26, 2024
@cmorgado
Copy link

cmorgado commented Mar 4, 2024

Can you provide the redemeer in plutus?

@NicolasEliasArias
Copy link
Author

@cmorgado How can I do that?

@cmorgado
Copy link

cmorgado commented Mar 4, 2024

show us your validator ... lucidValidator

@NicolasEliasArias
Copy link
Author

const lucidValidator: Script = {
  type: "PlutusV2",
  script: "58f2010000323232323232323222232325333008323232533300b002100114a06644646600200200644a66602200229404c8c94ccc040cdc78010028a511330040040013014002375c60240026eb0c038c03cc03cc03cc03cc03cc03cc03cc03cc020c008c020014dd71801180400399b8f375c6002600e00a91010d48656c6c6f2c20576f726c6421002300d00114984d958c94ccc020cdc3a400000226464a66601a601e0042930b1bae300d00130060041630060033253330073370e900000089919299980618070010a4c2c6eb8c030004c01401058c01400c8c014dd5000918019baa0015734aae7555cf2ab9f5742ae881",
};

@NicolasEliasArias
Copy link
Author

NicolasEliasArias commented Mar 5, 2024

2 observations:

in the lucid-cardano package for node js I can't find the utf8ToHex function.

Also tried with this validator and redeemer:

function utf8ToHex(str: string) {
  return Array.from(str).map(c => 
    c.charCodeAt(0) < 128 ? c.charCodeAt(0).toString(16) : 
    encodeURIComponent(c).replace(/\%/g,'').toLowerCase()
  ).join('');
}

const lucidValidator: Script = {
  type: "PlutusV2",
  script: toHex(cbor.encode(fromHex(scriptCompiledCode)))
};

const redeemer = Data.to(new Constr(0, [utf8ToHex("Hello, World!")]));

const tx = await lucid
    .newTx()
    .collectFrom([utxo], redeemer)
    .addSigner(await lucid.wallet.address())
    .attachSpendingValidator(lucidValidator)
    .complete();

And I'm getting this error:

Uncaught (in promise) Redeemer (Spend, 0): unexpected type tag at position 0: expected bytes (definite length)

@dchambers
Copy link

2 observations:

in the lucid-cardano package for node js I can't find the utf8ToHex function.

I just hit the same thing, and for posterity it was renamed to fromText from version 0.8.4.

@dchambers
Copy link

@NicolasEliasArias, did you end up managing to get past this as I'm now stuck on the same Failed to deserialise PlutusData using UnConstrData issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants