From c80f82a0b18e5a103f375139bbb9ead3b0fa9a95 Mon Sep 17 00:00:00 2001 From: Miguel Medeiros Date: Wed, 14 Apr 2021 17:27:28 -0300 Subject: [PATCH] v2.3.0 (#12) * FIX: getBlocks optional params * v2.3.0 - new minor version for mempool-js - Add support for Bisq API - Add support for Liquid API - Change the main object to export network objects. - Change README.md instructions. Co-authored-by: softsimon --- README-bisq.md | 150 ++++ README-bitcoin.md | 689 +++++++++++++++++ README-liquid.md | 757 +++++++++++++++++++ README.md | 675 ++--------------- examples/html/bisq/addresses.html | 21 + examples/html/bisq/blocks.html | 31 + examples/html/bisq/statistics.html | 19 + examples/html/bisq/transactions.html | 24 + examples/html/bitcoin/addresses.html | 35 + examples/html/bitcoin/blocks.html | 49 ++ examples/html/{ => bitcoin}/fees.html | 9 +- examples/html/{ => bitcoin}/mempool.html | 9 +- examples/html/bitcoin/transactions.html | 51 ++ examples/html/bitcoin/websocket.html | 36 + examples/html/{ => liquid}/addresses.html | 23 +- examples/html/liquid/assets.html | 33 + examples/html/{ => liquid}/blocks.html | 19 +- examples/html/liquid/fees.html | 22 + examples/html/liquid/mempool.html | 25 + examples/html/{ => liquid}/transactions.html | 29 +- examples/html/{ => liquid}/websocket.html | 19 +- examples/nodejs/addresses.ts | 23 - examples/nodejs/bisq/addresses.ts | 13 + examples/nodejs/bisq/blocks.ts | 23 + examples/nodejs/bisq/statistics.ts | 11 + examples/nodejs/bisq/transactions.ts | 17 + examples/nodejs/bitcoin/addresses.ts | 25 + examples/nodejs/bitcoin/blocks.ts | 41 + examples/nodejs/bitcoin/fees.ts | 19 + examples/nodejs/bitcoin/mempool.ts | 17 + examples/nodejs/bitcoin/transactions.ts | 41 + examples/nodejs/{ => bitcoin}/websocket.ts | 11 +- examples/nodejs/liquid/addresses.ts | 25 + examples/nodejs/liquid/assets.ts | 20 + examples/nodejs/{ => liquid}/blocks.ts | 16 +- examples/nodejs/{ => liquid}/fees.ts | 6 +- examples/nodejs/{ => liquid}/mempool.ts | 6 +- examples/nodejs/liquid/transactions.ts | 41 + examples/nodejs/liquid/websocket.ts | 28 + examples/nodejs/transactions.ts | 39 - src/app/addresses.ts | 39 - src/app/bisq/addresses.ts | 13 + src/app/bisq/blocks.ts | 27 + src/app/bisq/statistics.ts | 13 + src/app/bisq/transactions.ts | 21 + src/app/bitcoin/addresses.ts | 48 ++ src/app/{ => bitcoin}/blocks.ts | 27 +- src/app/{ => bitcoin}/fees.ts | 14 +- src/app/{ => bitcoin}/mempool.ts | 6 +- src/app/bitcoin/transactions.ts | 75 ++ src/app/bitcoin/websocket.ts | 14 + src/app/liquid/addresses.ts | 48 ++ src/app/liquid/assets.ts | 37 + src/app/liquid/blocks.ts | 79 ++ src/app/liquid/fees.ts | 33 + src/app/liquid/mempool.ts | 29 + src/app/liquid/transactions.ts | 75 ++ src/app/liquid/websocket.ts | 14 + src/app/transactions.ts | 71 -- src/app/websocket.ts | 14 - src/index.ts | 79 +- src/interfaces.ts | 213 ------ src/interfaces/bisq/addresses.ts | 13 + src/interfaces/bisq/blocks.ts | 18 + src/interfaces/bisq/statistics.ts | 11 + src/interfaces/bisq/transactions.ts | 46 ++ src/interfaces/bitcoin/addresses.ts | 30 + src/interfaces/bitcoin/blocks.ts | 36 + src/interfaces/bitcoin/fees.ts | 21 + src/interfaces/bitcoin/mempool.ts | 19 + src/interfaces/bitcoin/transactions.ts | 62 ++ src/interfaces/bitcoin/websockets.ts | 10 + src/interfaces/index.ts | 44 ++ src/interfaces/liquid/assets.ts | 27 + src/services/api.ts | 10 - src/services/api/index.ts | 43 ++ src/services/{wsClient.ts => ws/client.ts} | 14 +- src/services/{wsServer.ts => ws/server.ts} | 14 +- 78 files changed, 3394 insertions(+), 1160 deletions(-) create mode 100644 README-bisq.md create mode 100644 README-bitcoin.md create mode 100644 README-liquid.md create mode 100644 examples/html/bisq/addresses.html create mode 100644 examples/html/bisq/blocks.html create mode 100644 examples/html/bisq/statistics.html create mode 100644 examples/html/bisq/transactions.html create mode 100644 examples/html/bitcoin/addresses.html create mode 100644 examples/html/bitcoin/blocks.html rename examples/html/{ => bitcoin}/fees.html (73%) rename examples/html/{ => bitcoin}/mempool.html (77%) create mode 100644 examples/html/bitcoin/transactions.html create mode 100644 examples/html/bitcoin/websocket.html rename examples/html/{ => liquid}/addresses.html (61%) create mode 100644 examples/html/liquid/assets.html rename examples/html/{ => liquid}/blocks.html (67%) create mode 100644 examples/html/liquid/fees.html create mode 100644 examples/html/liquid/mempool.html rename examples/html/{ => liquid}/transactions.html (58%) rename examples/html/{ => liquid}/websocket.html (59%) delete mode 100644 examples/nodejs/addresses.ts create mode 100644 examples/nodejs/bisq/addresses.ts create mode 100644 examples/nodejs/bisq/blocks.ts create mode 100644 examples/nodejs/bisq/statistics.ts create mode 100644 examples/nodejs/bisq/transactions.ts create mode 100644 examples/nodejs/bitcoin/addresses.ts create mode 100644 examples/nodejs/bitcoin/blocks.ts create mode 100644 examples/nodejs/bitcoin/fees.ts create mode 100644 examples/nodejs/bitcoin/mempool.ts create mode 100644 examples/nodejs/bitcoin/transactions.ts rename examples/nodejs/{ => bitcoin}/websocket.ts (67%) create mode 100644 examples/nodejs/liquid/addresses.ts create mode 100644 examples/nodejs/liquid/assets.ts rename examples/nodejs/{ => liquid}/blocks.ts (64%) rename examples/nodejs/{ => liquid}/fees.ts (70%) rename examples/nodejs/{ => liquid}/mempool.ts (75%) create mode 100644 examples/nodejs/liquid/transactions.ts create mode 100644 examples/nodejs/liquid/websocket.ts delete mode 100644 examples/nodejs/transactions.ts delete mode 100644 src/app/addresses.ts create mode 100644 src/app/bisq/addresses.ts create mode 100644 src/app/bisq/blocks.ts create mode 100644 src/app/bisq/statistics.ts create mode 100644 src/app/bisq/transactions.ts create mode 100644 src/app/bitcoin/addresses.ts rename src/app/{ => bitcoin}/blocks.ts (60%) rename src/app/{ => bitcoin}/fees.ts (62%) rename src/app/{ => bitcoin}/mempool.ts (85%) create mode 100644 src/app/bitcoin/transactions.ts create mode 100644 src/app/bitcoin/websocket.ts create mode 100644 src/app/liquid/addresses.ts create mode 100644 src/app/liquid/assets.ts create mode 100644 src/app/liquid/blocks.ts create mode 100644 src/app/liquid/fees.ts create mode 100644 src/app/liquid/mempool.ts create mode 100644 src/app/liquid/transactions.ts create mode 100644 src/app/liquid/websocket.ts delete mode 100644 src/app/transactions.ts delete mode 100644 src/app/websocket.ts delete mode 100644 src/interfaces.ts create mode 100644 src/interfaces/bisq/addresses.ts create mode 100644 src/interfaces/bisq/blocks.ts create mode 100644 src/interfaces/bisq/statistics.ts create mode 100644 src/interfaces/bisq/transactions.ts create mode 100644 src/interfaces/bitcoin/addresses.ts create mode 100644 src/interfaces/bitcoin/blocks.ts create mode 100644 src/interfaces/bitcoin/fees.ts create mode 100644 src/interfaces/bitcoin/mempool.ts create mode 100644 src/interfaces/bitcoin/transactions.ts create mode 100644 src/interfaces/bitcoin/websockets.ts create mode 100644 src/interfaces/index.ts create mode 100644 src/interfaces/liquid/assets.ts delete mode 100644 src/services/api.ts create mode 100644 src/services/api/index.ts rename src/services/{wsClient.ts => ws/client.ts} (73%) rename src/services/{wsServer.ts => ws/server.ts} (74%) diff --git a/README-bisq.md b/README-bisq.md new file mode 100644 index 000000000..4f41e3816 --- /dev/null +++ b/README-bisq.md @@ -0,0 +1,150 @@ +# mempool**JS** - Bisq API + +Interface to access the Bisq API. + +[Back to home](./README-bitcoin.md) + +--- + +## **Features** + +- [Bitcoin](./README-bitcoin.md) +- Bisq + - Addresses + - [Get Address](#get-address) + - Blocks + - [Get Block](#get-block) + - [Get Blocks](#get-blocks) + - [Get Block Tip Height](#get-block-tip-height) + - Statistics + - Transactions + - [Get Transaction](#get-transaction) + - [Get Transactions](#get-transactions) +- [Liquid](./README-liquid.md) + +--- + +### **Get Address** + +Returns statistics about all Bisq transactions. + +[ [NodeJS Example](examples/nodejs/bisq/addresses.ts) ] [ [HTML Example](examples/html/bisq/addresses.html) ] [ [Top](#features) ] + +```js +const { + bisq: { addresses }, +} = mempoolJS(); + +const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz'; + +const myAddress = await addresses.getAddress({ address }); +console.log(myAddress); +``` + +### **Get Block** + +Returns all Bisq transactions that exist in a Bitcoin block. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ] + +```js +const { + bisq: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d'; + +const block = await blocks.getBlock({ hash }); +console.log(block); +``` + +### **Get Blocks** + +Returns `:length` Bitcoin blocks that contain Bisq transactions, starting from `:index`. + +**Parameters:** + +- {number} index +- {number} length + +[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ] + +```js +const { + bisq: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d'; + +const myBlocks = await blocks.getBlocks({ index: 0, length: 1 }); +console.log(myBlocks); +``` + +### **Get Blocks Tip Height** + +Returns the most recently processed Bitcoin block height processed by Bisq. + +[ [NodeJS Example](examples/nodejs/bisq/blocks.ts) ] [ [HTML Example](examples/html/bisq/blocks.html) ] [ [Top](#features) ] + +```js +const { + bisq: { blocks }, +} = mempoolJS(); + +const myBlocksHeight = await blocks.getBlocksTipHeight({ + index: 0, + length: 1, +}); +console.log(myBlocksHeight); +``` + +### **Get Stats** + +Returns statistics about all Bisq transactions. + +[ [NodeJS Example](examples/nodejs/bisq/statistics.ts) ] [ [HTML Example](examples/html/bisq/statistics.html) ] [ [Top](#features) ] + +```js +const { + bisq: { statistics }, +} = mempoolJS(); + +const stats = await statistics.getStats(); +console.log(stats); +``` + +### **Get Transaction** + +Returns details about a Bisq transaction. + +[ [NodeJS Example](examples/nodejs/bisq/transactions.ts) ] [ [HTML Example](examples/html/bisq/transactions.html) ] [ [Top](#features) ] + +```js +const { + bisq: { transactions }, +} = mempoolJS(); + +const txid = '4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5'; + +const tx = await transactions.getTx({ txid }); +console.log(tx); +``` + +### **Get Transactions** + +Returns details about a Bisq transactions. + +[ [NodeJS Example](examples/nodejs/bisq/transactions.ts) ] [ [HTML Example](examples/html/bisq/transactions.html) ] [ [Top](#features) ] + +```js +const { + bisq: { transactions }, +} = mempoolJS(); + +const txs = await transactions.getTxs({ index: 0, length: 1 }); +console.log(txs); +``` diff --git a/README-bitcoin.md b/README-bitcoin.md new file mode 100644 index 000000000..1cad89cdb --- /dev/null +++ b/README-bitcoin.md @@ -0,0 +1,689 @@ +# mempool**JS** - Bitcoin API + +Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs. + +[Back to home](#) + +--- + +## **Features** + +- Bitcoin + - Addresses + - [Get Address](#get-address) + - [Get Address Txs](#get-address-txs) + - [Get Address Txs Chain](#get-address-txs-chain) + - [Get Address Txs Mempool](#get-address-txs-mempool) + - [Get Address Txs Utxo](#get-address-txs-utxo) + - Assets + - [Get Asset](#get-asset) + - [Get Asset Txs](#get-asset-txs) + - [Get Asset Supply](#get-asset-supply) + - Blocks + - [Get Block](#get-block) + - [Get Block Status](#get-block-status) + - [Get Block Txs](#get-block-txs) + - [Get Block Txids](#get-block-txids) + - [Get Block Txid](#get-block-txid) + - [Get Block Raw](#get-block-raw) + - [Get Blocks Height](#get-blocks-height) + - [Get Blocks](#get-blocks) + - [Get Blocks Tip Height](#get-blocks-tip-height) + - [Get Blocks Tip Hash](#get-blocks-tip-hash) + - Fees + - [Get Fees Recommended](#get-fees-recommended) + - [Get Fees Mempool Blocks](#get-fees-mempool-blocks) + - Mempool + - [Get Mempool](#get-mempool) + - [Get Mempool Recent](#get-mempool-recent) + - [Get Mempool Txids](#get-mempool-txids) + - Transactions + - [Get Tx](#get-tx) + - [Get Tx Status](#get-tx-status) + - [Get Tx Hex](#get-tx-hex) + - [Get Tx Raw](#get-tx-raw) + - [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof) + - [Get Tx Merkle Proof](#get-tx-merkle-proof) + - [Get Tx Outspend](#get-tx-outspend) + - [Get Tx Outspends](#get-tx-outspends) + - [Post Tx Outspends]($post-tx-outspends) + - Websocket + - [Websocket Client](#websocket-client) + - [Websocket Server](#websocket-server) +- [Bisq](./README-bisq.md) +- [Liquid](./README-liquid.md) + +--- + +### **Get Address** + +Returns details about an address. Available fields: `address`, `chain_stats`, and `mempool_stats`. `{chain,mempool}\_stats` each contain an object with `tx_count`, `funded_txo_count`, `funded_txo_sum`, `spent_txo_count`, and `spent_txo_sum`. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const myAddress = await addresses.getAddress({ address }); +console.log(myAddress); +``` + +### **Get Address Txs** + +Get transaction history for the specified address/scripthash, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `:last_seen_txid`. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxs = await addresses.getAddressTxs({ address }); +console.log(addressTxs); +``` + +### **Get Address Txs Chain** + +Get confirmed transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxsChain = await addresses.getAddressTxsChain({ address }); +console.log(addressTxsChain); +``` + +### **Get Address Txs Mempool** + +Get unconfirmed transaction history for the specified `address/scripthash`. Returns up to 50 transactions (no paging). + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxsMempool = await addresses.getAddressTxsMempool({ address }); +console.log(addressTxsMempool); +``` + +### **Get Address Txs Utxo** + +Get the list of unspent transaction outputs associated with the `address/scripthash`. Available fields: `txid`, `vout`, `value`, and `status` (with the status of the funding tx). + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +```js +const { addresses } = mempoolJS(); + +const addressTxsUtxo = await addresses.getAddressTxsUtxo('15e10745f15593a...'); +console.log(addressTxsUtxo); +``` + +### **Get Block** + +Returns details about a block. Available fields: `id`, `height`, `version`, `timestamp`, `bits`, `nonce`, `merkle_root`, `tx_count`, `size`, `weight`, and `previousblockhash`. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const block = await blocks.getBlock({ hash }); +console.log(block); +``` + +### **Get Block Status** + +Returns the confirmation status of a block. Available fields: `in_best_chain` (boolean, false for orphaned blocks), `next_best` (the hash of the next block, only available for blocks in the best chain). + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockStatus = await blocks.getBlockStatus({ hash }); +console.log(blockStatus); +``` + +### **Get Block Txs** + +Returns a list of transactions in the block (up to 25 transactions beginning at start_index). Transactions returned here do not have the status field, since all the transactions share the same block and confirmation status. + +**Parameters:** + +- {string} params.hash +- {number} params.start_index + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxs = await blocks.getBlockTxs({ hash }); +console.log(blockTxs); +``` + +### **Get Block Txids** + +Returns a list of all txids in the block. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxids = await blocks.getBlockTxids({ hash }); +console.log(blockTxids); +``` + +### **Get Block Txid** + +Returns the transaction at index :index within the specified block. + +**Parameters:** + +- {string} params.hash +- {number} params.index + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); +console.log(blockTxid); +``` + +### **Get Block Raw** + +Returns the raw block representation in binary. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockRaw = await blocks.getBlockRaw({ hash }); +console.log(blockRaw); +``` + +### **Get Blocks Height** + +Returns the hash of the block currently at `:height`. + +**Parameters:** + +- {number} height + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const blockHeight = await blocks.getBlockHeight({ height: 0 }); +console.log(blockHeight); +``` + +### **Get Blocks** + +Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. + +**Parameters:** + +- {number} params.start_height + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const getBlocks = await blocks.getBlocks({ start_height: 9999 }); +console.log(getBlocks); +``` + +### **Get Blocks Tip Height** + +Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. + +**Parameters:** + +- {number} params.start_height + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const blocksTipHeight = await blocks.getBlocksTipHeight(); +console.log(blocksTipHeight); +``` + +### **Get Blocks Tip Hash** + +Returns the hash of the last block. + +[ [NodeJS Example](examples/nodejs/bitcoin/blocks.ts) ] [ [HTML Example](examples/html/bitcoin/blocks.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { blocks }, +} = mempoolJS(); + +const blocksTipHash = await blocks.getBlocksTipHash(); +console.log(blocksTipHash); +``` + +### **Get Fees Recommended** + +Returns our currently suggested fees for new transactions. + +[ [NodeJS Example](examples/nodejs/bitcoin/fees.ts) ] [ [HTML Example](examples/html/bitcoin/fees.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { fees }, +} = mempoolJS(); + +const feesRecommended = await fees.getFeesRecommended(); +console.log(feesRecommended); +``` + +### **Get Fees Mempool Blocks** + +Returns current mempool as projected blocks. + +[ [NodeJS Example](examples/nodejs/bitcoin/fees.ts) ] [ [HTML Example](examples/html/bitcoin/fees.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { fees }, +} = mempoolJS(); + +const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); +console.log(feesMempoolBlocks); +``` + +### **Get Mempool** + +Returns current mempool backlog statistics. + +[ [NodeJS Example](examples/nodejs/bitcoin/mempool.ts) ] [ [HTML Example](examples/html/bitcoin/mempool.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { mempool }, +} = mempoolJS(); + +const getMempool = await mempool.getMempool(); +console.log(getMempool); +``` + +### **Get Mempool Recent** + +Get a list of the last 10 transactions to enter the mempool. Each transaction object contains simplified overview data, with the following fields: `txid`, `fee`, `vsize`, and `value`. + +[ [NodeJS Example](examples/nodejs/bitcoin/mempool.ts) ] [ [HTML Example](examples/html/bitcoin/mempool.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { mempool }, +} = mempoolJS(); + +const getMempoolRecent = await mempool.getMempoolRecent(); +console.log(getMempoolRecent); +``` + +### **Get Mempool Txids** + +Get the full list of txids in the mempool as an array. The order of the `txids` is arbitrary and does not match bitcoind. + +[ [NodeJS Example](examples/nodejs/bitcoin/mempool.ts) ] [ [HTML Example](examples/html/bitcoin/mempool.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { mempool }, +} = mempoolJS(); + +const getMempoolTxids = await mempool.getMempoolTxids(); +console.log(getMempoolTxids); +``` + +### **Get Tx** + +Returns details about a transaction. Available fields: `txid`, `version`, `locktime`, `size`, `weight`, `fee`, `vin`, `vout`, and `status`. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const tx = await transactions.getTx({ txid }); +console.log(tx); +``` + +### **Get Tx Status** + +Returns the confirmation status of a transaction. Available fields: `confirmed` (boolean), `block_height` (optional), and `block_hash` (optional). + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txStatus = await transactions.getTxStatus({ txid }); +console.log(txStatus); +``` + +### **Get Tx Hex** + +Returns a transaction serialized as hex. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txHex = await transactions.getTxHex({ txid }); +console.log(txHex); +``` + +### **Get Tx Raw** + +Returns a transaction as binary data. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txRaw = await transactions.getTxRaw({ txid }); +console.log(txRaw); +``` + +### **Get Tx Merkle Block Proof** + +Returns a merkle inclusion proof for the transaction using bitcoind's merkleblock format. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid }); +console.log(txMerkleBlockProof); +``` + +### **Get Tx Merkle Proof** + +Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txMerkleProof = await transactions.getTxMerkleProof({ txid }); +console.log(txMerkleProof); +``` + +### **Get Tx Outspend** + +Returns the spending status of a transaction output. Available fields: `spent` (boolean), `txid` (optional), `vin` (optional), and `status` (optional, the status of the spending tx). + +**Parameters:** + +- {string} params.txid +- {number} params.vout + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txOutspend = await transactions.getTxOutspend({ + txid, + vout: 3, +}); +console.log(txOutspend); +``` + +### **Get Tx Outspends** + +Returns the spending status of all transaction outputs. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txOutspends = await transactions.getTxOutspends({ txid }); +console.log(txOutspends); +``` + +### **Post Tx Outspends** + +Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ] + +```js +const { + bitcoin: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const postTx = await transactions.postTx({ txid }); +console.log(postTx); +``` + +### **Websocket** + +Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you want pushed. Available: blocks, mempool-block, live-2h-chart, and stats. + +Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions. + +[ [NodeJS Example](examples/nodejs/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/bitcoin/addresses.html) ] [ [Top](#features) ] + +#### **Websocket Server** + +```js +const { + bitcoin: { websocket }, +} = mempoolJS(); + +const ws = websocket.initServer({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], +}); + +ws.on('message', function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.blocks) { + console.log(res.blocks); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res.mempoolBlocks) { + console.log(res.mempoolBlocks); + } +}); +``` + +#### **Websocket Client** + +```js +const { + bitcoin: { websocket }, +} = mempoolJS(); + +const ws = websocket.initClient({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], +}); + +ws.on('message', function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.blocks) { + console.log(res.blocks); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res.mempoolBlocks) { + console.log(res.mempoolBlocks); + } +}); +``` diff --git a/README-liquid.md b/README-liquid.md new file mode 100644 index 000000000..736320f90 --- /dev/null +++ b/README-liquid.md @@ -0,0 +1,757 @@ +# mempool**JS** - Bitcoin API + +Interface to access the Bitcoin `mainet`, `testnet`, `signet` APIs. + +[Back to home](./README.md) + +--- + +## **Features** + +- [Bitcoin](./README-bitcoin.md) +- [Bisq](./README-bisq.md) +- Liquid + - Addresses + - [Get Address](#get-address) + - [Get Address Txs](#get-address-txs) + - [Get Address Txs Chain](#get-address-txs-chain) + - [Get Address Txs Mempool](#get-address-txs-mempool) + - [Get Address Txs Utxo](#get-address-txs-utxo) + - Assets + - [Get Asset](#get-asset) + - [Get Asset Txs](#get-asset-txs) + - [Get Asset Supply](#get-asset-supply) + - Blocks + - [Get Block](#get-block) + - [Get Block Status](#get-block-status) + - [Get Block Txs](#get-block-txs) + - [Get Block Txids](#get-block-txids) + - [Get Block Txid](#get-block-txid) + - [Get Block Raw](#get-block-raw) + - [Get Blocks Height](#get-blocks-height) + - [Get Blocks](#get-blocks) + - [Get Blocks Tip Height](#get-blocks-tip-height) + - [Get Blocks Tip Hash](#get-blocks-tip-hash) + - Fees + - [Get Fees Recommended](#get-fees-recommended) + - [Get Fees Mempool Blocks](#get-fees-mempool-blocks) + - Mempool + - [Get Mempool](#get-mempool) + - [Get Mempool Recent](#get-mempool-recent) + - [Get Mempool Txids](#get-mempool-txids) + - Transactions + - [Get Tx](#get-tx) + - [Get Tx Status](#get-tx-status) + - [Get Tx Hex](#get-tx-hex) + - [Get Tx Raw](#get-tx-raw) + - [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof) + - [Get Tx Merkle Proof](#get-tx-merkle-proof) + - [Get Tx Outspend](#get-tx-outspend) + - [Get Tx Outspends](#get-tx-outspends) + - [Post Tx Outspends]($post-tx-outspends) + - Websocket + - [Websocket Client](#websocket-client) + - [Websocket Server](#websocket-server) + +--- + +### **Get Address** + +Returns details about an address. Available fields: `address`, `chain_stats`, and `mempool_stats`. `{chain,mempool}\_stats` each contain an object with `tx_count`, `funded_txo_count`, `funded_txo_sum`, `spent_txo_count`, and `spent_txo_sum`. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const myAddress = await addresses.getAddress({ address }); +console.log(myAddress); +``` + +### **Get Address Txs** + +Get transaction history for the specified address/scripthash, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `:last_seen_txid`. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxs = await addresses.getAddressTxs({ address }); +console.log(addressTxs); +``` + +### **Get Address Txs Chain** + +Get confirmed transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query. + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxsChain = await addresses.getAddressTxsChain({ address }); +console.log(addressTxsChain); +``` + +### **Get Address Txs Mempool** + +Get unconfirmed transaction history for the specified `address/scripthash`. Returns up to 50 transactions (no paging). + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { addresses }, +} = mempoolJS(); + +const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; + +const addressTxsMempool = await addresses.getAddressTxsMempool({ address }); +console.log(addressTxsMempool); +``` + +### **Get Address Txs Utxo** + +Get the list of unspent transaction outputs associated with the `address/scripthash`. Available fields: `txid`, `vout`, `value`, and `status` (with the status of the funding tx). + +**Parameters:** + +- {string} address + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { addresses } = mempoolJS(); + +const addressTxsUtxo = await addresses.getAddressTxsUtxo('15e10745f15593a...'); +console.log(addressTxsUtxo); +``` + +### **Get Asset** + +Returns information about a Liquid asset. + +**Parameters:** + +- {string} asset_id + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { assets }, +} = mempoolJS(); + +const asset_id = + '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; + +const asset = await assets.getAsset({ asset_id }); +console.log(asset); +``` + +### **Get Asset Txs** + +Returns transactions associated with the specified Liquid asset. For the network's native asset, returns a list of peg in, peg out, and burn transactions. For user-issued assets, returns a list of issuance, reissuance, and burn transactions. Does not include regular transactions transferring this asset. + +**Parameters:** + +- {string} asset_id +- {boolean} is_mempool + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { assets }, +} = mempoolJS(); + +const asset_id = + '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; + +const assetTxs = await assets.getAssetTxs({ asset_id, is_mempool: false }); +console.log(assetTxs); +``` + +### **Get Asset Supply** + +Get the current total supply of the specified asset. For the native asset (L-BTC), this is calculated as `[chain,mempool]\_stats.peg_in_amount` - `[chain,mempool]\_stats.peg_out_amount` - `[chain,mempool]\_stats.burned_amount`. For issued assets, this is calculated as `[chain,mempool]\_stats.issued_amount` - `[chain,mempool]\_stats.burned_amount`. Not available for assets with blinded issuances. If `/decimal` is specified, returns the supply as a decimal according to the asset's divisibility. Otherwise, returned in base units. + +**Parameters:** + +- {string} asset_id +- {boolean} decimal + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +```js +const { + liquid: { assets }, +} = mempoolJS(); + +const asset_id = + '6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d'; + +const assetSupply = await assets.getAssetSupply({ asset_id, decimal: false }); +console.log(assetSupply); +``` + +### **Get Block** + +Returns details about a block. Available fields: `id`, `height`, `version`, `timestamp`, `bits`, `nonce`, `merkle_root`, `tx_count`, `size`, `weight`, and `previousblockhash`. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const block = await blocks.getBlock({ hash }); +console.log(block); +``` + +### **Get Block Status** + +Returns the confirmation status of a block. Available fields: `in_best_chain` (boolean, false for orphaned blocks), `next_best` (the hash of the next block, only available for blocks in the best chain). + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockStatus = await blocks.getBlockStatus({ hash }); +console.log(blockStatus); +``` + +### **Get Block Txs** + +Returns a list of transactions in the block (up to 25 transactions beginning at start_index). Transactions returned here do not have the status field, since all the transactions share the same block and confirmation status. + +**Parameters:** + +- {string} hash +- {number} start_index + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxs = await blocks.getBlockTxs({ hash }); +console.log(blockTxs); +``` + +### **Get Block Txids** + +Returns a list of all txids in the block. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxids = await blocks.getBlockTxids({ hash }); +console.log(blockTxids); +``` + +### **Get Block Txid** + +Returns the transaction at index :index within the specified block. + +**Parameters:** + +- {string} hash +- {number} index + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); +console.log(blockTxid); +``` + +### **Get Block Raw** + +Returns the raw block representation in binary. + +**Parameters:** + +- {string} hash + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const hash = '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; + +const blockRaw = await blocks.getBlockRaw({ hash }); +console.log(blockRaw); +``` + +### **Get Blocks Height** + +Returns the hash of the block currently at `:height`. + +**Parameters:** + +- {number} height + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const blockHeight = await blocks.getBlockHeight({ height: 0 }); +console.log(blockHeight); +``` + +### **Get Blocks** + +Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. + +**Parameters:** + +- {number} start_height + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const getBlocks = await blocks.getBlocks({ start_height: 9999 }); +console.log(getBlocks); +``` + +### **Get Blocks Tip Height** + +Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. + +**Parameters:** + +- {number} start_height + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const blocksTipHeight = await blocks.getBlocksTipHeight(); +console.log(blocksTipHeight); +``` + +### **Get Blocks Tip Hash** + +Returns the hash of the last block. + +[ [NodeJS Example](examples/nodejs/liquid/blocks.ts) ] [ [HTML Example](examples/html/liquid/blocks.html) ] [ [Top](#features) ] + +```js +const { + liquid: { blocks }, +} = mempoolJS(); + +const blocksTipHash = await blocks.getBlocksTipHash(); +console.log(blocksTipHash); +``` + +### **Get Fees Recommended** + +Returns our currently suggested fees for new transactions. + +[ [NodeJS Example](examples/nodejs/liquid/fees.ts) ] [ [HTML Example](examples/html/liquid/fees.html) ] [ [Top](#features) ] + +```js +const { + liquid: { fees }, +} = mempoolJS(); + +const feesRecommended = await fees.getFeesRecommended(); +console.log(feesRecommended); +``` + +### **Get Fees Mempool Blocks** + +Returns current mempool as projected blocks. + +[ [NodeJS Example](examples/nodejs/liquid/fees.ts) ] [ [HTML Example](examples/html/liquid/fees.html) ] [ [Top](#features) ] + +```js +const { + liquid: { fees }, +} = mempoolJS(); + +const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); +console.log(feesMempoolBlocks); +``` + +### **Get Mempool** + +Returns current mempool backlog statistics. + +[ [NodeJS Example](examples/nodejs/liquid/mempool.ts) ] [ [HTML Example](examples/html/liquid/mempool.html) ] [ [Top](#features) ] + +```js +const { + liquid: { mempool }, +} = mempoolJS(); + +const getMempool = await mempool.getMempool(); +console.log(getMempool); +``` + +### **Get Mempool Recent** + +Get a list of the last 10 transactions to enter the mempool. Each transaction object contains simplified overview data, with the following fields: `txid`, `fee`, `vsize`, and `value`. + +[ [NodeJS Example](examples/nodejs/liquid/mempool.ts) ] [ [HTML Example](examples/html/liquid/mempool.html) ] [ [Top](#features) ] + +```js +const { + liquid: { mempool }, +} = mempoolJS(); + +const getMempoolRecent = await mempool.getMempoolRecent(); +console.log(getMempoolRecent); +``` + +### **Get Mempool Txids** + +Get the full list of txids in the mempool as an array. The order of the `txids` is arbitrary and does not match bitcoind. + +[ [NodeJS Example](examples/nodejs/liquid/mempool.ts) ] [ [HTML Example](examples/html/liquid/mempool.html) ] [ [Top](#features) ] + +```js +const { + liquid: { mempool }, +} = mempoolJS(); + +const getMempoolTxids = await mempool.getMempoolTxids(); +console.log(getMempoolTxids); +``` + +### **Get Tx** + +Returns details about a transaction. Available fields: `txid`, `version`, `locktime`, `size`, `weight`, `fee`, `vin`, `vout`, and `status`. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const tx = await transactions.getTx({ txid }); +console.log(tx); +``` + +### **Get Tx Status** + +Returns the confirmation status of a transaction. Available fields: `confirmed` (boolean), `block_height` (optional), and `block_hash` (optional). + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txStatus = await transactions.getTxStatus({ txid }); +console.log(txStatus); +``` + +### **Get Tx Hex** + +Returns a transaction serialized as hex. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txHex = await transactions.getTxHex({ txid }); +console.log(txHex); +``` + +### **Get Tx Raw** + +Returns a transaction as binary data. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txRaw = await transactions.getTxRaw({ txid }); +console.log(txRaw); +``` + +### **Get Tx Merkle Block Proof** + +Returns a merkle inclusion proof for the transaction using bitcoind's merkleblock format. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid }); +console.log(txMerkleBlockProof); +``` + +### **Get Tx Merkle Proof** + +Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txMerkleProof = await transactions.getTxMerkleProof({ txid }); +console.log(txMerkleProof); +``` + +### **Get Tx Outspend** + +Returns the spending status of a transaction output. Available fields: `spent` (boolean), `txid` (optional), `vin` (optional), and `status` (optional, the status of the spending tx). + +**Parameters:** + +- {string} txid +- {number} vout + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txOutspend = await transactions.getTxOutspend({ + txid, + vout: 3, +}); +console.log(txOutspend); +``` + +### **Get Tx Outspends** + +Returns the spending status of all transaction outputs. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const txOutspends = await transactions.getTxOutspends({ txid }); +console.log(txOutspends); +``` + +### **Post Tx Outspends** + +Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success. + +**Parameters:** + +- {string} txid + +[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ] + +```js +const { + liquid: { transactions }, +} = mempoolJS(); + +const txid = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; + +const postTx = await transactions.postTx({ txid }); +console.log(postTx); +``` + +### **Websocket** + +Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you want pushed. Available: blocks, mempool-block, live-2h-chart, and stats. + +Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions. + +[ [NodeJS Example](examples/nodejs/liquid/addresses.ts) ] [ [HTML Example](examples/html/liquid/addresses.html) ] [ [Top](#features) ] + +#### **Websocket Server** + +```js +const { + liquid: { websocket }, +} = mempoolJS(); + +const ws = websocket.initServer({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], +}); + +ws.on('message', function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.blocks) { + console.log(res.blocks); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res.mempoolBlocks) { + console.log(res.mempoolBlocks); + } +}); +``` + +#### **Websocket Client** + +```js +const { + liquid: { websocket }, +} = mempoolJS(); + +const ws = websocket.initClient({ + options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], +}); + +ws.on('message', function incoming(data) { + const res = JSON.parse(data.toString()); + if (res.blocks) { + console.log(res.blocks); + } + if (res.mempoolInfo) { + console.log(res.mempoolInfo); + } + if (res.transactions) { + console.log(res.transactions); + } + if (res.mempoolBlocks) { + console.log(res.mempoolBlocks); + } +}); +``` diff --git a/README.md b/README.md index 47100dfd0..52ad325ce 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,13 @@ # Mempool JS API -[![npm version](https://badge.fury.io/js/%40mempool%2Fmempool-js.svg)](https://badge.fury.io/js/%40mempool%2Fmempool-js) -[![NPM](https://img.shields.io/david/mempool/mempool-js.svg)](https://david-dm.org/mempool/mempool-js#info=dependencies) -[![Known Vulnerabilities](https://snyk.io/test/github/mempool/mempool-js/badge.svg)](https://snyk.io/test/github/mempool/mempool-js) -[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) +[![npm version](https://img.shields.io/npm/v/@mempool/mempool-js.svg?style=flat-square)](https://www.npmjs.org/package/mempool-js) +[![NPM](https://img.shields.io/david/mempool/mempool-js.svg?style=flat-square)](https://david-dm.org/mempool/mempool-js#info=dependencies) +[![Known Vulnerabilities](https://snyk.io/test/github/mempool/mempool-js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/mempool-js) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT) -NPM package module for Mempool JS API. +NPM package module for Mempool APIs. -Documentation: [https://mempool.space/api](https://mempool.space/api) - ---- - -## Features - -- [Installation](#installation) - - [CommonJS](#commonjs) - - [NodeJS](#es-modules) -- [Usage](#usage) - - - Addresses - - [Get Address](#get-address) - - [Get Address Txs](#get-address-txs) - - [Get Address Txs Chain](#get-address-txs-chain) - - [Get Address Txs Mempool](#get-address-txs-mempool) - - [Get Address Txs Utxo](#get-address-txs-utxo) - - Blocks - - [Get Block](#get-block) - - [Get Block Status](#get-block-status) - - [Get Block Txs](#get-block-txs) - - [Get Block Txids](#get-block-txids) - - [Get Block Txid](#get-block-txid) - - [Get Block Raw](#get-block-raw) - - [Get Blocks Height](#get-blocks-height) - - [Get Blocks](#get-blocks) - - [Get Blocks Tip Height](#get-blocks-tip-height) - - [Get Blocks Tip Hash](#get-blocks-tip-hash) - - Fees - - [Get Fees Recommended](#get-fees-recommended) - - [Get Fees Mempool Blocks](#get-fees-mempool-blocks) - - Mempool - - [Get Mempool](#get-mempool) - - [Get Mempool Recent](#get-mempool-recent) - - [Get Mempool Txids](#get-mempool-txids) - - Transactions - - [Get Tx](#get-tx) - - [Get Tx Status](#get-tx-status) - - [Get Tx Hex](#get-tx-hex) - - [Get Tx Raw](#get-tx-raw) - - [Get Tx Merkle Block Proof](#get-tx-merkle-block-proof) - - [Get Tx Merkle Proof](#get-tx-merkle-proof) - - [Get Tx Outspend](#get-tx-outspend) - - [Get Tx Outspends](#get-tx-outspends) - - [Post Tx Outspends]($post-tx-outspends) - - [Websocket](#websocket) - -- [Contribute](#contribute) -- [License](#license) +[https://mempool.tools/mempool-js](https://mempool.tools/mempool-js) --- @@ -63,7 +15,7 @@ Documentation: [https://mempool.space/api](https://mempool.space/api) ### **ES Modules** -First, install the npm module. +Install the npm module. ```bash # npm @@ -75,602 +27,69 @@ $ yarn add @mempool/mempool-js Or if you're not into package management, just [download a ZIP](https://github.com/mempool/mempool-js/archive/refs/heads/main.zip) file. -Then import the module. +Import the module. ```js import mempoolJS from '@mempool/mempool-js'; -const { - addresses, - blocks, - fees, - mempool, - transactions, - websocket, -} = mempoolJS(); -``` +// default mempool.space endpoints +const { bitcoin, bisq, liquid } = mempoolJS(); -**Custom Endpoints (Optional)** - -You can set your custom **API** and **WS** endpoints. - -```js -import mempoolJS from '@mempool/mempool-js'; - -const { address } = mempoolJS({ - apiEndpoint: 'https://mempool.space/api/', - websocketEndpoint: 'wss://mempool.space/api/v1/ws', +// (alternative) your custom endpoints +const { bitcoin, bisq, liquid } = mempoolJS({ + homespace: 'mempool.space', }); ``` ### **CommonJS** -We provide you our own link to `mempool-js`: +Include the line below in the `head` tag of your html file. ```html ``` -If you want to run your own build, run the script: - -```bash -# npm -$ npm run build - -# yarn -$ yarn build -``` - -And, include the script located on the `dist` folder. - -```html - -``` - -Now, you have an access to a variable function to access the API methods. +Call `mempoolJS` function to access the API methods. ```js -const { - addresses, - blocks, - fees, - mempool, - transactions, - websocket, -} = mempoolJS(); -``` +// default mempool.space endpoints +const { bitcoin, bisq, liquid } = mempoolJS(); -## **Usage** - -### **Get Address** - -Returns details about an address. Available fields: `address`, `chain_stats`, and `mempool_stats`. `{chain,mempool}\_stats` each contain an object with `tx_count`, `funded_txo_count`, `funded_txo_sum`, `spent_txo_count`, and `spent_txo_sum`. - -Parameters: - -- {string} address - Address id. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { addresses } = mempoolJS(); - -const address = await addresses.getAddress('15e10745f15593a...'); -console.log(address); -``` - -### **Get Address Txs** - -Get transaction history for the specified address/scripthash, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using `:last_seen_txid` (see below). - -Parameters: - -- {string} address - Address id. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { addresses } = mempoolJS(); - -const addressTxs = await addresses.getAddressTxs('15e10745f15593a...'); -console.log(addressTxs); -``` - -### **Get Address Txs Chain** - -Get confirmed transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query. - -Parameters: - -- {string} address - Address id. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { addresses } = mempoolJS(); - -const addressTxsChain = await addresses.getAddressTxsChain( - '15e10745f15593a...' -); -console.log(addressTxsChain); -``` - -### **Get Address Txs Mempool** - -Get unconfirmed transaction history for the specified address/scripthash. Returns up to 50 transactions (no paging). - -Parameters: - -- {string} address - Address id. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { addresses } = mempoolJS(); - -const addressTxsMempool = await addresses.getAddressTxsMempool( - '15e10745f15593a...' -); -console.log(addressTxsMempool); -``` - -### **Get Address Txs Utxo** - -Get unconfirmed transaction history for the specified address/scripthash. Returns up to 50 transactions (no paging). - -Parameters: - -- {string} address - Address id. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { addresses } = mempoolJS(); - -const addressTxsUtxo = await addresses.getAddressTxsUtxo('15e10745f15593a...'); -console.log(addressTxsUtxo); -``` - -### **Get Block** - -Returns details about a block. Available fields: `id`, `height`, `version`, `timestamp`, `bits`, `nonce`, `merkle_root`, `tx_count`, `size`, `weight`, and `previousblockhash`. - -Parameters: - -- {string} hash - Hash from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const block = await blocks.getBlock('000000000000000015dc...'); -console.log(block); -``` - -### **Get Block Status** - -Returns the confirmation status of a block. Available fields: `in_best_chain` (boolean, false for orphaned blocks), `next_best` (the hash of the next block, only available for blocks in the best chain). - -Parameters: - -- {string} hash - Hash from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockStatus = await blocks.getBlockStatus('000000000000000015dc...'); -console.log(blockStatus); -``` - -### **Get Block Txs** - -Returns a list of transactions in the block (up to 25 transactions beginning at start_index). Transactions returned here do not have the status field, since all the transactions share the same block and confirmation status. - -Parameters: - -- {Object} params - Params object. -- {string} params.hash - Hash from a block -- {number} params.start_index - Default: 25 - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockTxs = await blocks.getBlockTxs({ - hash: '000000000000000015dc...', -}); -console.log(blockTxs); -``` - -### **Get Block Txids** - -Returns a list of all txids in the block. - -Parameters: - -- {string} hash - Hash from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockTxids = await blocks.getBlockTxids('000000000000000015dc...'); -console.log(blockTxids); -``` - -### **Get Block Txid** - -Returns the transaction at index :index within the specified block. - -Parameters: - -- {Object} params - Params object. -- {string} params.hash - Hash from a block -- {number} params.index - Index - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockTxid = await blocks.getBlockTxid({ - hash: '000000000000000015dc...', - index: 218, -}); -console.log(blockTxids); -``` - -### **Get Block Raw** - -Returns the raw block representation in binary. - -Parameters: - -- {string} hash - Hash from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockRaw = await blocks.getBlockRaw('000000000000000015dc...'); -console.log(blockRaw); -``` - -### **Get Blocks Height** - -Returns the hash of the block currently at `:height`. - -Parameters: - -- {number} height - Height number from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blockHeight = await blocks.getBlockHeight(42); -console.log(blockHeight); -``` - -### **Get Blocks** - -Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. - -Parameters: - -- {Object} params - Params object. -- {number} params.start_height - Height from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const getBlocks = await blocks.getBlocks({ - start_height: 66666, -}); -console.log(getBlocks); -``` - -### **Get Blocks Tip Height** - -Returns the 10 newest blocks starting at the tip or at `:start_height` if specified. - -Parameters: - -- {Object} params - Params object. -- {number} params.start_height - Height from a block - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blocksTipHeight = await blocks.getBlocksTipHeight(); -console.log(blocksTipHeight); -``` - -### **Get Blocks Tip Hash** - -Returns the hash of the last block. - -[ [NodeJS Example](examples/nodejs/blocks.ts) ] [ [HTML Example](examples/html/blocks.html) ] [ [Top](#features) ] - -```js -const { blocks } = mempoolJS(); - -const blocksTipHash = await blocks.getBlocksTipHash(); -console.log(blocksTipHash); -``` - -### **Get Fees Recommended** - -Returns our currently suggested fees for new transactions. - -[ [NodeJS Example](examples/nodejs/fees.ts) ] [ [HTML Example](examples/html/fees.html) ] [ [Top](#features) ] - -```js -const { fees } = mempoolJS(); - -const feesRecommended = await fees.getFeesRecommended(); -console.log(feesRecommended); -``` - -### **Get Fees Mempool Blocks** - -Returns current mempool as projected blocks. - -[ [NodeJS Example](examples/nodejs/fees.ts) ] [ [HTML Example](examples/html/fees.html) ] [ [Top](#features) ] - -```js -const { fees } = mempoolJS(); - -const feesMempoolBlocks = await fees.getFeesMempoolBlocks(); -console.log(feesMempoolBlocks); -``` - -### **Get Mempool** - -Returns current mempool backlog statistics. - -[ [NodeJS Example](examples/nodejs/mempool.ts) ] [ [HTML Example](examples/html/mempool.html) ] [ [Top](#features) ] - -```js -const { mempool } = mempoolJS(); - -const getMempool = await mempool.getMempool(); -console.log(getMempool); -``` - -### **Get Mempool Txids** - -Get the full list of txids in the mempool as an array. The order of the `txids` is arbitrary and does not match bitcoind. - -[ [NodeJS Example](examples/nodejs/mempool.ts) ] [ [HTML Example](examples/html/mempool.html) ] [ [Top](#features) ] - -```js -const { mempool } = mempoolJS(); - -const getMempoolTxids = await mempool.getMempoolTxids(); -console.log(getMempoolTxids); -``` - -### **Get Mempool Recent** - -Get a list of the last 10 transactions to enter the mempool. Each transaction object contains simplified overview data, with the following fields: `txid`, `fee`, `vsize`, and `value`. - -[ [NodeJS Example](examples/nodejs/mempool.ts) ] [ [HTML Example](examples/html/mempool.html) ] [ [Top](#features) ] - -```js -const { mempool } = mempoolJS(); - -const getMempoolRecent = await mempool.getMempoolRecent(); -console.log(getMempoolRecent); -``` - -### **Get Tx** - -Returns details about a transaction. Available fields: `txid`, `version`, `locktime`, `size`, `weight`, `fee`, `vin`, `vout`, and `status`. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const tx = await transactions.getTx('15e10745f15593...'); -console.log(tx); -``` - -### **Get Tx Status** - -Returns the confirmation status of a transaction. Available fields: `confirmed` (boolean), `block_height` (optional), and `block_hash` (optional). - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txStatus = await transactions.getTxStatus('15e10745f15593...'); -console.log(txStatus); -``` - -### **Get Tx Hex** - -Returns a transaction serialized as hex. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txHex = await transactions.getTxHex('15e10745f15593...'); -console.log(txHex); -``` - -### **Get Tx Raw** - -Returns a transaction as binary data. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txRaw = await transactions.getTxRaw('15e10745f15593...'); -console.log(txRaw); -``` - -### **Get Tx Merkle Block Proof** - -Returns a merkle inclusion proof for the transaction using bitcoind's merkleblock format. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txMerkleBlockProof = await transactions.getTxMerkleBlockProof( - '15e10745f15593...' -); -console.log(txMerkleBlockProof); -``` - -### **Get Tx Merkle Proof** - -Returns a merkle inclusion proof for the transaction using Electrum's blockchain.transaction.get_merkle format. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txMerkleProof = await transactions.getTxMerkleProof('15e10745f15593...'); -console.log(txMerkleProof); -``` - -### **Get Tx Outspend** - -Returns the spending status of a transaction output. Available fields: `spent` (boolean), `txid` (optional), `vin` (optional), and `status` (optional, the status of the spending tx). - -Parameters: - -- {Object} params - Params object. -- {string} params.txid - Transactions id. -- {number} params.vout - Vout number. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txOutspend = await transactions.getTxOutspend({ - txid: '15e10745f15593...', - vout: 3, -}); -console.log(txOutspend); -``` - -### **Get Tx Outspends** - -Returns the spending status of all transaction outputs. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const txOutspends = await transactions.getTxOutspends('15e10745f15593...'); -console.log(txOutspends); -``` - -### **Post Tx Outspends** - -Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The `txid` will be returned on success. - -Parameters: - -- {string} txid - Transactions id. - -[ [NodeJS Example](examples/nodejs/transactions.ts) ] [ [HTML Example](examples/html/transactions.html) ] [ [Top](#features) ] - -```js -const { transactions } = mempoolJS(); - -const postTx = await transactions.postTx('15e10745f15593...'); -console.log(postTx); -``` - -### **Websocket** - -Default push: `{ action: 'want', data: ['blocks', ...] }` to express what you want pushed. Available: blocks, mempool-block, live-2h-chart, and stats. - -Push transactions related to address: `{ 'track-address': '3PbJ...bF9B' }` to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions. - -[ [NodeJS Example](examples/nodejs/addresses.ts) ] [ [HTML Example](examples/html/addresses.html) ] [ [Top](#features) ] - -```js -const { websocket } = mempoolJS(); - -const ws = websocket.initServer({ - options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], -}); - -ws.on('message', function incoming(data) { - const res = JSON.parse(data.toString()); - if (res.blocks) { - res.blocks.forEach((block: { height }) => { - console.log(block.height); - }); - } - if (res.mempoolInfo) { - console.log(res.mempoolInfo); - } - if (res.transactions) { - console.log(res.transactions); - } - if (res.mempoolBlocks) { - console.log(res.mempoolBlocks); - } +// (alternative) your custom endpoints +const { bitcoin, bisq, liquid } = mempoolJS({ + homespace: 'mempool.space', }); ``` --- +## **Features** + +- [Bitcoin](./README-bitcoin.md) + - [Addresses](./README-bitcoin.md#get-address) + - [Blocks](./README-bitcoin.md#get-blocks) + - [Fees](./README-bitcoin.md#get-fees) + - [Mempool](./README-bitcoin.md#get-mempool) + - [Transactions](./README-bitcoin.md#get-transactions) + - [Websocket Client](./README-bitcoin.md#Websocket-Client) + - [Websocket Server](./README-bitcoin.md#Websocket-Server) +- [Bisq](./README-bisq.md#get-address) + - [Addresses](./README-bisq.md#get-address) + - [Blocks](./README-bisq.md#get-blocks) + - [Statistics](./README-bisq.md#get-statistics) + - [Transactions](./README-bisq.md#get-transactions) +- [Liquid](./README-liquid.md#get-address) + - [Addresses](./README-liquid.md#get-address) + - [Assets](./README-liquid.md#get-address) + - [Blocks](./README-liquid.md#get-address) + - [Fees](./README-liquid.md#get-address) + - [Mempool](./README-liquid.md#get-address) + - [Transactions](./README-liquid.md#get-address) + - [Websocket Client](./README-liquid.md#Websocket-Client) + - [Websocket Server](./README-liquid.md#Websocket-Server) + +--- + ## **Contributing** Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change. diff --git a/examples/html/bisq/addresses.html b/examples/html/bisq/addresses.html new file mode 100644 index 000000000..94865f4ee --- /dev/null +++ b/examples/html/bisq/addresses.html @@ -0,0 +1,21 @@ + + + + Page Title + + + + + diff --git a/examples/html/bisq/blocks.html b/examples/html/bisq/blocks.html new file mode 100644 index 000000000..a6d62d3c0 --- /dev/null +++ b/examples/html/bisq/blocks.html @@ -0,0 +1,31 @@ + + + + Page Title + + + + + diff --git a/examples/html/bisq/statistics.html b/examples/html/bisq/statistics.html new file mode 100644 index 000000000..88889dda9 --- /dev/null +++ b/examples/html/bisq/statistics.html @@ -0,0 +1,19 @@ + + + + Page Title + + + + + diff --git a/examples/html/bisq/transactions.html b/examples/html/bisq/transactions.html new file mode 100644 index 000000000..551aafaed --- /dev/null +++ b/examples/html/bisq/transactions.html @@ -0,0 +1,24 @@ + + + + Page Title + + + + + diff --git a/examples/html/bitcoin/addresses.html b/examples/html/bitcoin/addresses.html new file mode 100644 index 000000000..90efe911c --- /dev/null +++ b/examples/html/bitcoin/addresses.html @@ -0,0 +1,35 @@ + + + + Page Title + + + + + diff --git a/examples/html/bitcoin/blocks.html b/examples/html/bitcoin/blocks.html new file mode 100644 index 000000000..7404bb00f --- /dev/null +++ b/examples/html/bitcoin/blocks.html @@ -0,0 +1,49 @@ + + + + Page Title + + + + + diff --git a/examples/html/fees.html b/examples/html/bitcoin/fees.html similarity index 73% rename from examples/html/fees.html rename to examples/html/bitcoin/fees.html index 6271d313c..ee71d855a 100644 --- a/examples/html/fees.html +++ b/examples/html/bitcoin/fees.html @@ -2,13 +2,12 @@ Page Title - + + + + + + diff --git a/examples/html/bitcoin/websocket.html b/examples/html/bitcoin/websocket.html new file mode 100644 index 000000000..a1e82a530 --- /dev/null +++ b/examples/html/bitcoin/websocket.html @@ -0,0 +1,36 @@ + + + + Page Title + + + + + diff --git a/examples/html/addresses.html b/examples/html/liquid/addresses.html similarity index 61% rename from examples/html/addresses.html rename to examples/html/liquid/addresses.html index ec7203464..89115491d 100644 --- a/examples/html/addresses.html +++ b/examples/html/liquid/addresses.html @@ -2,29 +2,30 @@ Page Title - + + + + + diff --git a/examples/html/blocks.html b/examples/html/liquid/blocks.html similarity index 67% rename from examples/html/blocks.html rename to examples/html/liquid/blocks.html index f28a89799..e2c39832e 100644 --- a/examples/html/blocks.html +++ b/examples/html/liquid/blocks.html @@ -2,36 +2,35 @@ Page Title - + + + + + diff --git a/examples/html/liquid/mempool.html b/examples/html/liquid/mempool.html new file mode 100644 index 000000000..6b02c6c8d --- /dev/null +++ b/examples/html/liquid/mempool.html @@ -0,0 +1,25 @@ + + + + Page Title + + + + + diff --git a/examples/html/transactions.html b/examples/html/liquid/transactions.html similarity index 58% rename from examples/html/transactions.html rename to examples/html/liquid/transactions.html index 20313254a..c7c8cb7b3 100644 --- a/examples/html/transactions.html +++ b/examples/html/liquid/transactions.html @@ -2,35 +2,34 @@ Page Title - + +