<p>I don't suggest using <code>cardano-graphql</code> to submit a transaction: every time the node gets behind the tip of the blockchain, it fails.</p>
<p><a href="https://ogmios.dev/" rel="nofollow noreferrer"><code>ogmios</code></a> is much more reliable for this regard.</p>
<p>You can submit a transaction using the following code:</p>
<pre><code>const WebSocket = require('ws');
const client = new WebSocket(&quot;wss://ogmios-api.testnet.dandelion.link&quot;);

function wsp(methodname, args) {
    client.send(JSON.stringify({
        type: &quot;jsonwsp/request&quot;,
        version: &quot;1.0&quot;,
        servicename: &quot;ogmios&quot;,
        methodname,
        args
    }));
}

client.once('open', () =&gt; {
    const submit =
      &quot;g6QAgYJYIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGCglg5AQEBAQEBAQEB&quot;+
      &quot;AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBGgAehICC&quot;+
      &quot;WDkBAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC&quot;+
      &quot;AgICAgIaAHgXXAIaAAH6pAMZHkahAIGCWCABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&quot;+
      &quot;AAAAAFhA169grjPSrzUUEcFEXHlZBSaZC/pzy7NzK1TvMi2qFC5ohAI0EPi+PBbpvVIHbyuz&quot;+
      &quot;a/ON/gNKnwRljp9WGXq4D/Y=&quot;;

    wsp(&quot;SubmitTx&quot;, { submit });
});

client.on('message', function(msg) {
    const response = JSON.parse(msg);
    console.log(response);
    client.close();
}); 
</code></pre>
<p>Keep in mind that, in this example, the transaction is already in base64 format (<code>submit</code> variable). To convert from hex to base64, you need to use these helpers:</p>
<pre><code>const arrayBufferToBase64=( buffer )=&gt; {
  var binary = '';
  var bytes = new Uint8Array( buffer );
  var len = bytes.byteLength;
  for (var i = 0; i &lt; len; i++) {
      binary += String.fromCharCode( bytes[ i ] );
  }
  return Buffer.from(binary, &quot;binary&quot;).toString(&quot;base64&quot;);
}

const fromHex=(hex)=&gt;Buffer.from(hex,&quot;hex&quot;);

const bytes = arrayBufferToBase64(fromHex(txHex));
</code></pre>
<p>Then you can pass <code>bytes</code> to <code>wsp</code> function.</p>

CC BY-SA 4.0
2022-06-01T02:40:44.973Z
2022-06-01T04:43:13.743Z
2022-06-01T04:43:13.743Z
Falcon Stakepool
<p>I'm getting this error when trying to submit a transaction using <code>graphql</code>:</p>
<pre><code>{
  &quot;errors&quot;: [
    {
      &quot;message&quot;: &quot;Deserialization failed in Transaction.metadata because: Expected null, found other type&quot;,
      &quot;locations&quot;: [
        {
          &quot;line&quot;: 2,
          &quot;column&quot;: 3
        }
      ],
      &quot;path&quot;: [
        &quot;submitTransaction&quot;
      ],
      &quot;extensions&quot;: {
        &quot;code&quot;: &quot;INTERNAL_SERVER_ERROR&quot;,
        &quot;exception&quot;: {
          &quot;stacktrace&quot;: [
            &quot;Error: Deserialization failed in Transaction.metadata because: Expected null, found other type&quot;,
            &quot;    at Object.&lt;anonymous&gt; (/app/packages/api-cardano-db-hasura/dist/executableSchema.js:77:43)&quot;,
            &quot;    at Generator.throw (&lt;anonymous&gt;)&quot;,
            &quot;    at rejected (/app/packages/api-cardano-db-hasura/dist/executableSchema.js:6:65)&quot;,
            &quot;    at processTicksAndRejections (internal/process/task_queues.js:95:5)&quot;
          ]
        }
      }
    }
  ],
  &quot;data&quot;: null
}
</code></pre>
<p>What is this trying to say?</p>
<p>The transaction has been built using <code>cardano-serialization-lib</code>.</p>
<p>I'm 100% sure the transaction is correct because it's been accepted using other methods.</p>

<cardano-serialization-lib><cardano-graphql><tx>
What's the correct way of submitting a transaction using cardano-graphql?
# What's the correct way of submitting a transaction using cardano-graphql?

(Asked by: username_0 on 2022-05-30)

I'm getting this error when trying to submit a transaction using graphql:
{
  "errors": [
    {
      "message": "Deserialization failed in Transaction.metadata because: Expected null, found other type",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "submitTransaction"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Deserialization failed in Transaction.metadata because: Expected null, found other type",
            "    at Object. (/app/packages/api-cardano-db-hasura/dist/executableSchema.js:77:43)",
            "    at Generator.throw ()",
            "    at rejected (/app/packages/api-cardano-db-hasura/dist/executableSchema.js:6:65)",
            "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
          ]
        }
      }
    }
  ],
  "data": null
}

What is this trying to say?
The transaction has been built using cardano-serialization-lib.
I'm 100% sure the transaction is correct because it's been accepted using other methods.

**Tags:** cardano-serialization-lib, cardano-graphql, tx

---

## 1 answers

### Answer by username_0 on 2022-06-01. Score: 1 | Accepted answer

I don't suggest using cardano-graphql to submit a transaction: every time the node gets behind the tip of the blockchain, it fails.
ogmios is much more reliable for this regard.
You can submit a transaction using the following code:
const WebSocket = require('ws');
const client = new WebSocket("wss://ogmios-api.testnet.dandelion.link");

function wsp(methodname, args) {
    client.send(JSON.stringify({
        type: "jsonwsp/request",
        version: "1.0",
        servicename: "ogmios",
        methodname,
        args
    }));
}

client.once('open', () => {
    const submit =
      "g6QAgYJYIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGCglg5AQEBAQEBAQEB"+
      "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBGgAehICC"+
      "WDkBAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC"+
      "AgICAgIaAHgXXAIaAAH6pAMZHkahAIGCWCABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+
      "AAAAAFhA169grjPSrzUUEcFEXHlZBSaZC/pzy7NzK1TvMi2qFC5ohAI0EPi+PBbpvVIHbyuz"+
      "a/ON/gNKnwRljp9WGXq4D/Y=";

    wsp("SubmitTx", { submit });
});

client.on('message', function(msg) {
    const response = JSON.parse(msg);
    console.log(response);
    client.close();
}); 

Keep in mind that, in this example, the transaction is already in base64 format (submit variable). To convert from hex to base64, you need to use these helpers:
const arrayBufferToBase64=( buffer )=> {
  var binary = '';
  var bytes = new Uint8Array( buffer );
  var len = bytes.byteLength;
  for (var i = 0; i < len; i++) {
      binary += String.fromCharCode( bytes[ i ] );
  }
  return Buffer.from(binary, "binary").toString("base64");
}

const fromHex=(hex)=>Buffer.from(hex,"hex");

const bytes = arrayBufferToBase64(fromHex(txHex));

Then you can pass bytes to wsp function.


---

