transactions – Error 400 when pushing tx hex to mempool.space’s API

[ad_1]

  1. Create a transaction and get hex:
0200000000010119335721e24061cab07c9caf3a9ed331b85511af3d6be38ef37bda93ddce49880100000000fdffffff02a086010000000000160014243588dda3d0560986069a55b386c1d3417ecc2e19a903000000000016001469577cafbaa617f64cd468ff51a578aeb85cfcf202473044022066c1314f71f05cf1c2e27298dc056d7b66cbc2bab0b3d536ad084fa577d9a0650220349102e2d151309b7820ff848d39ba28c6763f972e90359300dbfd3131ff4fa1012102cc2868604a6db586db0d72654f71835a3d6c20e465eea4597509963f47bd3c65dbe91f00
  1. Use Postman to send a POST request with:

    URL: https://mempool.space/testnet/api/tx

    Body: Transaction hex

  2. It will return transaction id:

23b0c4ce54e13a846e6a9f50f11019071f98c53f1d82ea9c674de1c7a94af45a

postman

Doing same thing using JavaScript:

  1. Click on </>

postman-code

  1. Select one of the options for JavaScript. I used JavaScript-Fetch:
var myHeaders = new Headers();
myHeaders.append("Content-Type", "text/plain");

var raw = "020000000001015af44aa9c7e14d679cea821d3fc5981f071910f1509f6a6e843ae154cec4b0230100000000fdffffff02a0860100000000001600141c97aee9cf15d8a9016c3a98c5a503ed49d012caec2102000000000016001463924d833ecc676de6dec0cf6c72c6c94bc1c5350247304402206fbb992ce8f8e35b5c229dae731709c7d82de404d882e62271ce6e7551e103ff02203e94d589766db4e583d862b6ad3951fe62c498b11fdeae85bfc37ef61e2af13a0121039072d28be7d83a8f4b1983da7a74d2bd28e80ee79d4ee2bf603e101865099378dce91f00";

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://mempool.space/testnet/api/tx", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

  1. Run this on https://jsfiddle.net/ and you will get the transaction id in response:

fiddle

bd0306a1fa6e262949c9856ebcea61c0857067e1d2c856d0216a9cf871e4a377

[ad_2]

Source link

Leave a Comment