Cardano-wallet malformed tx payload

Hi, I’m trying to submit a already signed tx from cardano-cli using cardano-wallet endpoint https://localhost:8090/v2/proxy/transactions

the transaction look like this:

   txBody = {
        "type": "Tx MaryEra",
        "description": "",
        "cborHex": "83a400818258202d7928a59fcba5bf71c40fe6428a301ffda4d2fa681e5357051970436462b89400018282583900c0e88694ab569f42453eb950fb4ec14cb50f4d5d26ac83fdec2c505d818bcebf1df51c84239805b8a330d68fdbc3c047c12bb4c3172cb9391a002b335f825839003d2d9ceb1a47bc1b62b7498ca496b16a7b4bbcc6d97ede81ba8621ebd6d947875fcf4845ef3a5f08dd5522581cf6de7b9c065379cbb3754d1a001e8480021a00029361031a01672b7ea1008182582073dd733cc50d594cb89d3ac67287b02dae00982fc800e9c9c9d1bb282b56122558404d0cb4e4f1cc415ddcf546871f075d0ca6e0c2620cd784b06c21c9b86e4403cb7a115038487576dcb20e7820e9d0dc93ab2a737ed9d0a71a77bc1e12f7c4dd0ef6"
    }

I just don’t know how to pass it to the endpoint using Content-Type application/octet-stream. In the API doc it says:

string <binary>
Signed transaction message binary blob.

I’m using javascript for this and have tried passing the cborHex directly, using Buffer.from(txBody.cborHex).toString('base64') and the whole json Buffer.from(JSON.stringify(txBody)).toString('base64') but alway got the same result:

{
  "code": "malformed_tx_payload", 
  "message": "I couldn't verify that the payload has the c…node. Please check the format and try again."
}

Also I’ve noticed from the swagger specification that the endpoint support a JSON payload but no idea al the structure of it. Any idea how to pass the signed tx?

cardano-wallet is not supposed to work in the way you’re trying with other modules, you can submit your tx using CLI itself against node that runs with the wallet

I know I can submit the tx using CLI, I just want to know how is it using proxy/transactions endpoint. If I cannot use an already signed tx from cardano-cli then where is the signed tx coming from (I thought no distinction should be made here)? Maybe an example will be useful in this case.

The tx is created and submitted by wallet API and does not necessarily follow same semantics. For cardano-wallet component, you cannot manually construct transaction by selecting UTXOs. It is not aimed for such usage. This component is aimed at users who dont want to worry about setting fees or electing UTXOs manually - also, it will store the keys encrypted with spending password locally on wallet instance db. Thus, it does not make sense for many use cases (like third party wallet/integrations/…) to use this component .

Similar to other posts, your requirements highly point that you should be using cardano-address/cardano-rosetta/serialisation-lib against node instead.

(Also, since you’ve already used CLI to construct transaction - you should submit it against node using CLI)

I totally got your point, but cardano-wallet is shipped with this endpoint proxy/transactions entitled “Submit External Transaction”. So we should expect it has some use cases right? Judging by the endpoint title and description: “Submits a transaction that was created and signed outside of cardano-wallet.” why is my approach wrong? More important, what is the right way to use it?

1 Like

Sure, and as mentioned above - it is valid for user/custodial entity’s transactions, nowhere does it set an expectation of manually constructed transaction using cardano-cli.

If you want to use cardano-wallet component/API to submit tx , you can only create transaction as per the documentation and example in wallet API.

Maybe you are not following me, Yes I do want to use cardano-wallet to submit a tx through the endpoint proxy/transactions. So I need to figure it out how this method receive the payload, this is the original question.

I mean, how the payload for proxy/transactions looks like and where it is coming from (Maybe my approach is wrong, but should be examples that point out how to use it).

Hi Fivo, have you maybe found the solution?
I am also having problem with this, trying to submit external signed transaction…

Hi @Dorijan_Jelincic I did. You can check this github issue: Cardano-wallet malformed tx payload on Submit External Transaction endpoint · Issue #2610 · input-output-hk/cardano-wallet · GitHub.

TLDR: In my case I was using a swagger code generation for the API https://editor.swagger.io and it seems the generated code for typescript/axios has some issues (or maybe is the API definition).

I ended up with this snippet code for submit external tx:

postExternalTransaction: async (body?: Object, options: any = {}): Promise<RequestArgs> => {
            ...
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
            const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
            localVarRequestOptions.data =  needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || "");

            return {
                url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
                options: localVarRequestOptions,
            };
        },
    }

The problem was specifically here:

  const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';
  localVarRequestOptions.data =  needsSerialization ? JSON.stringify(body !== undefined ? body : {}) : (body || "");

Here the body (a Buffer) is being “stringified” but we need to pass it as is.

So replacing the 2 above lines for this:

localVarRequestOptions.data = body;

the body will be passed as is

Thank you for quick answer.
I was wondering what is the original transactions that you are sending?
Is it whole json file like

{
    "type": "Tx MaryEra",
    "description": "",
    "cborHex": "83a400818258...."
}

or just
83a4008182582041ba39fcb8faaca27aa2de857aca3…

@Fivo89 I found what the problem was, I upgraded the cardano-wallet and now it works…
Thank you

1 Like