Submit transaction with cardano-cli which got built and signed with nodejs-cardano-wasm - formatting error

Hey guys,

I am trying to submit a transaction via cardano-cli which got built and signed by a nodejs app using cardano-wasm. I tried the following approach:

The result I got from the cli:

error: Command failed: cardano-cli transaction submit --tx-file /tx-files/jpg-tx46774.signed --mainnet

Command failed: transaction submit Error: Failed to decode neither the cli’s serialisation format nor the ledger’s CDDL serialisation format. TextEnvelope error: /tx-files/jpg-tx46774.signed: TextEnvelope aeson decode error: Error in $: Failed reading: not a valid json value

TextEnvelopeCddl error: /tx-files/jpg-tx46774.signed: Could not JSON decode TextEnvelopeCddl file at: /tx-files/jpg-tx46774.signed Error: Error in $: Failed reading: not a valid json value

Besides txToSubmit.to_bytes() I have also tried to write the tx-file with content of
txToSubmit.to_json()
txToSubmit.to_hex()

But I get the same result.

Does anyone know in which format the tx-file has to be and how to get it there? Submitting via Blockfrost “txSubmit(txToSubmit.to_bytes())” works flawlessly, but I want to switch to cardano-cli :slight_smile:

I figured out, that the tx.signed file has to be in a similar format like this:


{
    "type":"Witnessed Tx ShelleyEra",
    "description":"",
    "cborHex":"xxx(cbor-built-by-cardano-wasm)"
}

(Is the type “Witnessed Tx ShelleyEra” even correct for submitting signed transactions on mainnet?)

Could someone provide me a sample tx.signed file?

When submitting the transaction via cardano-cli (cardano-cli transaction submit --mainnet --tx-file /tx-files/tx.signed) I receive the following error:

Command failed: transaction submit Error: Failed to decode neither the cli’s serialisation format nor the ledger’s CDDL serialisation format. TextEnvelope error: /tx-files//tx.signed: TextEnvelope type error: Expected one of: TxSignedByron, TxSignedShelley, Tx AllegraEra, Tx MaryEra, Tx AlonzoEra, Tx BabbageEra Actual: Witnessed Tx ShelleyEra

TextEnvelopeCddl error: /tx-files/tx.signed: TextEnvelopeCDDL CBOR decoding error: DecoderErrorDeserialiseFailure “Shelley Tx” (DeserialiseFailure 1 “Size mismatch when decoding \nRecord RecD.\nExpected 4, but found 3.”)

EDIT2:

Okay its working now :slight_smile:
I played around with cli and created a new address, supplied it with ada, built and signed a transaction and thats what I got:

{
  "type": "Witnessed Tx BabbageEra",
  "description": "Ledger Cddl Format",
  "cborHex": "xxx (cbor)"
}

I was able to submit a transaction with this code:

const txToSubmit = CardanoWasm.Transaction.new(signedTransaction.body(), keyWitness, undefined);
const tempTxName = '/tx-files/tx' + Math.round(Math.random() * 99999) + '.signed';
fs.writeFileSync(tempTxName, JSON.stringify({
            type: 'Witnessed Tx BabbageEra',
            description: 'Ledger Cddl Format',
            cborHex: txToSubmit.to_hex()
        }));
exec('cardano-cli transaction submit --tx-file ' + tempTxName + ' --mainnet', (error, stdout, stderr) => {
  if (error) {
    console.log(`error: ${error.message}`);
    return;
  }
  if (stderr) {
    console.log(`stderr: ${stderr}`);
    return;
  }
  console.log(`stdout: ${stdout}`);
});