3

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

the signed 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. The API doc says the payload should be:

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 always got the same response:

{
  "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 and taking a look to the cardano-wallet's source code here:

newtype PostExternalTransactionData = PostExternalTransactionData
    { payload :: ByteString
    } deriving (Eq, Generic, Show)

I thought the structure should be some like this:

{
  "payload": ?// some binary blob here that I can't find. I've tried with: 
              // Buffer.from(txBody.cborHex).toString('base64') and 
              // Buffer.from(JSON.stringify(txBody)).toString('base64')
}

Any idea how to construct the payload and pass the signed tx?

leobelizquierdo
  • 1,648
  • 12
  • 20

1 Answers1

0

This code tells me that when decoding external (sealed) transaction the wallet tries Base 16 encoding first and if that fails then it tries Base 64:

instance FromJSON (ApiT SealedTx) where
    parseJSON v = do
        tx <- parseSealedTxBytes @'Base16 v <|> parseSealedTxBytes @'Base64 v
        pure $ ApiT tx

After that BytesString is passed to this function https://github.com/input-output-hk/cardano-node/blob/5faa1d2bb85ae806ec51fa4c576dec2670c67c7a/cardano-api/src/Cardano/Api/SerialiseCBOR.hs#L32 together with the currentNodeEra that node is running.

(Each era has a different way of decoding)

It could be (I am not sure) that node is running say Alonzo but you're submitting a Mary-encoded Tx. In which case the decoding might fail.

I hope this helps.

Yura Lazarev
  • 76
  • 1
  • 4