<p>I tested your code and apparently the code is right but your Hex string is wrong.
The API response is as follows:</p>
<p><code>data: 'sendrawtransaction RPC error: {&quot;code&quot;:-22,&quot;message&quot;:&quot;TX decode failed. Make sure the tx has at least one input.&quot;}'</code></p>
<p>Make sure that you have right Hex to post your tx. :)</p>

CC BY-SA 4.0
2021-09-09T11:22:11.940Z
2021-09-09T11:22:11.940Z
Miguel Medeiros
<p>I am using the code syntax provided by mempool.space for a POST transaction request from their website here:</p>
<p><a href="https://mempool.space/api" rel="nofollow noreferrer">https://mempool.space/api</a></p>
<pre><code>const mempoolJS = require(&quot;@mempool/mempool.js&quot;)

const init = async () =&gt; {
  
  const { bitcoin: { transactions } } = mempoolJS({
    hostname: 'mempool.space'
  });

  const txHex = '0200000001fd5b5fcd1cb066c27cfc9fda5428b9be850b81ac440ea51f1ddba2f987189ac1010000008a4730440220686a40e9d2dbffeab4ca1ff66341d06a17806767f12a1fc4f55740a7af24c6b5022049dd3c9a85ac6c51fecd5f4baff7782a518781bbdd94453c8383755e24ba755c01410436d554adf4a3eb03a317c77aa4020a7bba62999df633bba0ea8f83f48b9e01b0861d3b3c796840f982ee6b14c3c4b7ad04fcfcc3774f81bff9aaf52a15751fedfdffffff02416c00000000000017a914bc791b2afdfe1e1b5650864a9297b20d74c61f4787d71d0000000000001976a9140a59837ccd4df25adc31cdad39be6a8d97557ed688ac00000000';

  const txid = await transactions.postTx({ txHex });
  console.log(txid);
          
};
init();
</code></pre>
<p>This code snippet isn't working for me. I keep getting a <code>UnhandledPromiseRejectionWarning: Error: Request failed with status code 400</code>. I am unsure if it's because I am using the require instead of import? Or I am not correctly sending a POST request? Or not handling the Promise syntax correctly?</p>
<p>Would appreciate suggestions.</p>

CC BY-SA 4.0
2021-09-04T12:46:08.930Z
Would I be entering all this into the same .js file?
jiamijiang
<transactions><api><raw-transaction><mempool.space>
Error 400 when pushing tx hex to mempool.space's API
jiamijiang
# Error 400 when pushing tx hex to mempool.space's API

(Asked by: username_0 on 2021-09-04)

I am using the code syntax provided by mempool.space for a POST transaction request from their website here:

<https://mempool.space/api>

```
const mempoolJS = require("@mempool/mempool.js")

const init = async () => {
  
  const { bitcoin: { transactions } } = mempoolJS({
    hostname: 'mempool.space'
  });

  const txHex = '0200000001fd5b5fcd1cb066c27cfc9fda5428b9be850b81ac440ea51f1ddba2f987189ac1010000008a4730440220686a40e9d2dbffeab4ca1ff66341d06a17806767f12a1fc4f55740a7af24c6b5022049dd3c9a85ac6c51fecd5f4baff7782a518781bbdd94453c8383755e24ba755c01410436d554adf4a3eb03a317c77aa4020a7bba62999df633bba0ea8f83f48b9e01b0861d3b3c796840f982ee6b14c3c4b7ad04fcfcc3774f81bff9aaf52a15751fedfdffffff02416c00000000000017a914bc791b2afdfe1e1b5650864a9297b20d74c61f4787d71d0000000000001976a9140a59837ccd4df25adc31cdad39be6a8d97557ed688ac00000000';

  const txid = await transactions.postTx({ txHex });
  console.log(txid);
          
};
init();

```

This code snippet isn't working for me. I keep getting a `UnhandledPromiseRejectionWarning: Error: Request failed with status code 400`. I am unsure if it's because I am using the require instead of import? Or I am not correctly sending a POST request? Or not handling the Promise syntax correctly?

Would appreciate suggestions.

**Tags:** transactions, api, raw-transaction, mempool.space

> **Comments:**
> **username_0**: Would I be entering all this into the same .js file?  

---

## 1 answers

### Answer by username_1 on 2021-09-09. Score: 3

I tested your code and apparently the code is right but your Hex string is wrong.
The API response is as follows:

`data: 'sendrawtransaction RPC error: {"code":-22,"message":"TX decode failed. Make sure the tx has at least one input."}'`

Make sure that you have right Hex to post your tx. :)


---

