0

I get this error when trying to unlock funds from an UTXO in a contract address:

Uncaught (in promise) "Redeemer (Spend, 0): Attempted to apply a non-function:\n\nCon(\n    Unit,\n)\n\nExBudget {\n    mem: 12788611,\n    cpu: 9492522265,\n}\n\n"

is there any problem in the following code?

async function unlock(ref: OutRef, from: SpendingValidator): Promise<TxHash> {
  const [utxo] = await lucid.utxosByOutRef([ref]);

  const tx = await lucid
    .newTx()
    .collectFrom( [utxo], Data.to(new Constr(0,[])) )
    .addSigner(await lucid.wallet.address())
    .attachSpendingValidator(from)
    .complete();

  const signedTx = await tx
    .sign()
    .complete();
 
  return signedTx.submit();
}

here is how I take the validator:

const validator = await readValidator();

async function readValidator(): Promise<SpendingValidator> {
  const validator = JSON.parse(await Deno.readTextFile("plutus.json")).validators[0];
  return {
    type: "PlutusV2",
    script: toHex(cbor.encode(fromHex(validator.compiledCode))), 
    // some alchemy with Uint8Array and other codes that returns pretty much initial thing but a little different
  };
}
3
  • What data structure is specting the Validator? What type is the redeemer? what language you used to make the validator? Commented Apr 26 at 3:55
  • The redeemer is Void, while the datum is simply a ByteArray type Datum {hex: ByteArray} validator { fn check(datum: Datum, _redeemer: Void) -> Bool {complexfunc(datum.hex)}and I used Aiken. Could it be that the problem resides in the function that processes the Datum's ByteArray inside the Aiken validator? rather than a problem with Lucid? Although when I test the validator in Aiken it works fine. Commented Apr 27 at 19:06
  • I tried just with a simple equality as validator and I still get the same error. this is the utxo I am trying to use: { txHash: "a183...", outputIndex: 0, assets: { lovelace: 10000000n }, address: "addr_test1wr...", datumHash: undefined, datum: "d8799f43849480ff", scriptRef: undefined } so it shouldn't be related to my validator, but an error related to Lucid code but then it is so simple and boilerplate that I don't really know where to look anymore. Commented Apr 28 at 9:19

1 Answer 1

1

You probably already did, but check that you are actually passing the utxos to the tx, and check that the datum is the right one, the datum seems to be hash or its just a bytestring? how does quering the utxo on cli or looking for the datum in explorers look?

It seems no valid utxo is available for spending or the validator itself its wrong.

take a look at this post that seems to be dealing with a similar problem.

Lucid Error "End of input in bytes"

how are you importing your validators cbor into Lucid?, you can use Lucid blueprint parser examples, or if you where using a CLI ready json file (created with aiken blueprint convert) you can copy paste the cborhex, or import it and parse it.

1
  • thanks, I added to the question how I import the validator from the aiken build json - method shown in an aiken example. and here is tha datum which seem correct to me: preview.cexplorer.io/datum/… Commented Apr 30 at 22:51

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.