0

so i'm runing this to prompt a transaction on nami wallet, sign and submit. the ideal scenario was to nami wallet submit transaction for herself but somehow that is not happening, so i tried to submit via blockfrost api.

the script that i paste on devtools console:

// Replace this with your transaction data
const cborEncodedTransaction =
  // Your CBOR encoded transaction data here
  "MY_TX_CBOR";

// Replace this with your API key from Blockfrost
const apiKey = "PROJECT_ID_BLOCKFROST";

async function signAndSubmitTransaction(cborEncodedTransaction) {
  try {
    // Check if Nami Wallet is available
    if (!window.cardano) {
      throw new Error("Nami Wallet is not available. Make sure you have the Nami Wallet extension installed.");
    }

    // Sign the transaction using Nami Wallet
    const partialSign = true; // Set this to true to enable partial signing
    const transactionWitnessSet = await window.cardano.signTx(cborEncodedTransaction, partialSign);

    // Convert the transactionWitnessSet to a hex-encoded string
    const signedCborTransaction = transactionWitnessSet;
    console.log("Signed Transaction (hex-encoded):", signedCborTransaction);

    // Submit the transaction using Blockfrost API
    console.log("Submitting transaction to Blockfrost...");
    console.log("CBOR Encoded Transaction with Witness:", signedCborTransaction);

    const response = await fetch("https://cardano-mainnet.blockfrost.io/api/v0/tx/submit", {
      method: "POST",
      headers: {
        "Content-Type": "application/cbor",
        "Project_id": apiKey,
      },
      body: signedCborTransaction,
    });

    console.log("Blockfrost Response Status:", response.status);
    console.log("Blockfrost Response Data:", await response.json());

    if (!response.ok) {
      const errorData = await response.json();
      throw new Error(`Blockfrost API error: ${errorData.error}, ${errorData.message}`);
    }

    console.log("Transaction submitted successfully.");
  } catch (error) {
    console.error("Error signing or submitting transaction:", error);
    throw error;
  }
}

// Call the signAndSubmitTransaction function with the transaction data
signAndSubmitTransaction(cborEncodedTransaction);

the error that i get:

{
    "error": "Bad Request",
    "message": "\"transaction read error RawCborDecodeError [DecoderErrorDeserialiseFailure \\\"Byron Tx\\\" (DeserialiseFailure 0 \\\"expected list len\\\"),DecoderErrorDeserialiseFailure \\\"Shelley Tx\\\" (DeserialiseFailure 0 \\\"expected list len or indef\\\"),DecoderErrorDeserialiseFailure \\\"Shelley Tx\\\" (DeserialiseFailure 0 \\\"expected list len or indef\\\"),DecoderErrorDeserialiseFailure \\\"Shelley Tx\\\" (DeserialiseFailure 0 \\\"expected list len or indef\\\"),DecoderErrorDeserialiseFailure \\\"Shelley Tx\\\" (DeserialiseFailure 0 \\\"expected list len or indef\\\"),DecoderErrorDeserialiseFailure \\\"Shelley Tx\\\" (DeserialiseFailure 0 \\\"expected list len or indef\\\")]\"",
    "status_code": 400
}

the nami window pops up with the correct transaction for me to signed it, and after that the error happens.

1 Answer 1

0

Your variable signedCborTransaction is just key witnesses for inputs being spent in this transaction that belong to your wallet, specifically, it's CBOR of transaction_witness_set with only entries for 0th key as per this CDDL specification. You would need to add this witness to your original transaction (cborEncodedTransaction) and then submit it.

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.