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
};
}
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.{ 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.