MeshJS / mesh

An open-source library to advance Web3 development on Cardano
https://meshjs.dev
Apache License 2.0
200 stars 55 forks source link

`OUR_PRINCESS_IS_IN_ANOTHER_CASTLE` while trying to use `redeemValue` #224

Closed dchambers closed 3 months ago

dchambers commented 3 months ago

Hi Mesh :wave:.

I've been able to create some UTxOs which were spent against a validator script written in Aiken. However, when I try to redeem those UTxOs in a follow-up transaction using redeemValue I get the following error:

Error: [AppWallet] An error occurred during signTx: Error: An error occurred during signTx: Error: Missing key witness for: OUR_PRINCESS_IS_IN_ANOTHER_CASTLE..

Here's the code I'm using:

import { Transaction } from "@meshsdk/core";
import type { Action, PlutusScript, UTxO } from "@meshsdk/core";

import blueprint from "../plutus.json" with { type: "json" };
import { blockfrostProvider, wallet, walletAddress } from "./utils.ts";

const registrationTxHash =
  "647fe68803a863e67ddc4bf0ba47f024422d24bf2a2d3b9dc5285056525eb574";

export const validatorScript = (validatorName: string): PlutusScript => {
  const validators = blueprint.validators;
  const requestedValidator = validators.find(
    (nextValidator) => nextValidator.title === validatorName
  );

  if (!requestedValidator) {
    throw new Error(
      `The requested validator '${validatorName}' could not be found!`
    );
  }

  return {
    version: "V2",
    // code: toHex(cbor.encode(fromHex(requestedValidator.compiledCode))),
    code: requestedValidator.compiledCode,
  };
};

const openChannelTx = new Transaction({ initiator: wallet });

const spendingValidatorScript = validatorScript("serpentine.spendingValidator");

openChannelTx.setCollateral(
  (await blockfrostProvider.fetchAddressUTxOs(walletAddress)) as UTxO[]
);

const registrationUTxOs = await blockfrostProvider.fetchUTxOs(
  registrationTxHash
);

console.log("registrationUTxOs[0]: ", registrationUTxOs[0]);

openChannelTx.redeemValue({
  value: registrationUTxOs[0],
  script: spendingValidatorScript as PlutusScript | UTxO,
  redeemer: {
    data: {
      alternative: 0,
      fields: ["PublishValidatorSeedGroup"],
    },
  } as Action,
});

const unsignedOpenChannelTx = await openChannelTx.build();
const signedOpenChannelTx = await wallet.signTx(unsignedOpenChannelTx);
const openChannelTxHash = await wallet.submitTx(signedOpenChannelTx);

console.log(`openChannelTxHash: ${openChannelTxHash}`);

Is there anything I'm doing that's obviously wrong please?

abdelkrimdev commented 3 months ago

please make sure to set partial sign to true when spending from a script wallet.signTx(unsignedOpenChannelTx, true)

dchambers commented 3 months ago

Yes, that worked! Thank you so much @abdelkrimdev :pray: