UNPKG

@thorwallet/xchain-litecoin

Version:

Custom Litecoin client and utilities used by XChainJS clients

34 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.broadcastTx = void 0; const tslib_1 = require("tslib"); const axios_1 = tslib_1.__importDefault(require("axios")); /** * Broadcast transaction. * * @see https://developer.bitcoin.org/reference/rpc/sendrawtransaction.html * * @returns {string} Transaction ID. */ const broadcastTx = ({ txHex, auth, nodeUrl }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { try { const uniqueId = new Date().getTime().toString(); // for unique id const response = (yield axios_1.default.post(nodeUrl, { jsonrpc: '2.0', method: 'sendrawtransaction', params: [txHex], id: uniqueId, }, { auth, })).data; if (response.error) { throw new Error(`failed to broadcast a transaction: ${response.error}`); } return response.result; } catch (error) { return Promise.reject(error); } }); exports.broadcastTx = broadcastTx; //# sourceMappingURL=node-api.js.map