* 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 <softsimon@users.noreply.github.com>
This commit is contained in:
Miguel Medeiros
2021-04-14 17:27:28 -03:00
committed by GitHub
parent 70d31f2062
commit c80f82a0b1
78 changed files with 3394 additions and 1160 deletions

150
README-bisq.md Normal file
View File

@@ -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);
```

689
README-bitcoin.md Normal file
View File

@@ -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);
}
});
```

757
README-liquid.md Normal file
View File

@@ -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);
}
});
```

675
README.md
View File

@@ -1,61 +1,13 @@
# Mempool JS API # Mempool JS API
[![npm version](https://badge.fury.io/js/%40mempool%2Fmempool-js.svg)](https://badge.fury.io/js/%40mempool%2Fmempool-js) [![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)](https://david-dm.org/mempool/mempool-js#info=dependencies) [![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)](https://snyk.io/test/github/mempool/mempool-js) [![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)](https://opensource.org/licenses/MIT) [![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) [https://mempool.tools/mempool-js](https://mempool.tools/mempool-js)
---
## 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)
--- ---
@@ -63,7 +15,7 @@ Documentation: [https://mempool.space/api](https://mempool.space/api)
### **ES Modules** ### **ES Modules**
First, install the npm module. Install the npm module.
```bash ```bash
# npm # 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. 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 ```js
import mempoolJS from '@mempool/mempool-js'; import mempoolJS from '@mempool/mempool-js';
const { // default mempool.space endpoints
addresses, const { bitcoin, bisq, liquid } = mempoolJS();
blocks,
fees,
mempool,
transactions,
websocket,
} = mempoolJS();
```
**Custom Endpoints (Optional)** // (alternative) your custom endpoints
const { bitcoin, bisq, liquid } = mempoolJS({
You can set your custom **API** and **WS** endpoints. homespace: 'mempool.space',
```js
import mempoolJS from '@mempool/mempool-js';
const { address } = mempoolJS({
apiEndpoint: 'https://mempool.space/api/',
websocketEndpoint: 'wss://mempool.space/api/v1/ws',
}); });
``` ```
### **CommonJS** ### **CommonJS**
We provide you our own link to `mempool-js`: Include the line below in the `head` tag of your html file.
```html ```html
<script type="text/javascript" src="https://mempool.space/mempool.js"></script> <script type="text/javascript" src="https://mempool.space/mempool.js"></script>
``` ```
If you want to run your own build, run the script: Call `mempoolJS` function to access the API methods.
```bash
# npm
$ npm run build
# yarn
$ yarn build
```
And, include the script located on the `dist` folder.
```html
<script type="text/javascript" src="./dist/mempool.min.js"></script>
```
Now, you have an access to a variable function to access the API methods.
```js ```js
const { // default mempool.space endpoints
addresses, const { bitcoin, bisq, liquid } = mempoolJS();
blocks,
fees,
mempool,
transactions,
websocket,
} = mempoolJS();
```
## **Usage** // (alternative) your custom endpoints
const { bitcoin, bisq, liquid } = mempoolJS({
### **Get Address** homespace: 'mempool.space',
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);
}
}); });
``` ```
--- ---
## **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** ## **Contributing**
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change. Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

View File

@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { addresses },
} = mempoolJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { blocks },
} = mempoolJS();
const hash =
'000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const block = await blocks.getBlock({ hash });
console.log(block);
const myBlocks = await blocks.getBlocks({ index: 0, length: 1 });
console.log(myBlocks);
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { statistics },
} = mempoolJS();
const stats = await statistics.getStats();
console.log(stats);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bisq: { transactions },
} = mempoolJS();
const txid = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bitcoin: { addresses },
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({
address,
});
console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bitcoin: { blocks },
} = mempoolJS();
const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash });
console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(getBlocks);
const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(blocksTipHeight);
const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -2,13 +2,12 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { fees } = mempoolJS(); const {
bitcoin: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);

View File

@@ -2,13 +2,12 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { mempool } = mempoolJS(); const {
bitcoin: { mempool },
} = mempoolJS();
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bitcoin: { transactions },
} = mempoolJS();
const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus);
const txHex = await transactions.getTxHex({ txid });
console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({
txid,
});
console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({
txid,
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends);
// const postTx = await transactions.postTx({ txid });
// console.log(postTx);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
bitcoin: { websocket },
} = mempoolJS();
// console.log(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);
}
});
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -2,29 +2,30 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { addresses } = mempoolJS(); const {
liquid: { addresses },
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC'; const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const addressTest = await addresses.getAddress(address); const myAddress = await addresses.getAddress({ address });
console.log(addressTest); console.log(myAddress);
const addressTxs = await addresses.getAddressTxs(address); const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs); console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain(address); const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain); console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool(address); const addressTxsMempool = await addresses.getAddressTxsMempool({
address,
});
console.log(addressTxsMempool); console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo(address); const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo); console.log(addressTxsUtxo);
}; };
init(); init();

View File

@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
liquid: { assets },
} = mempoolJS();
const asset_id = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const asset = await assets.getAsset({ asset_id });
console.log(asset);
const assetTxs = await assets.getAssetTxs({
asset_id,
is_mempool: false,
});
console.log(assetTxs);
const assetSupply = await assets.getAssetSupply({
asset_id,
decimal: false,
});
console.log(assetSupply);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -2,36 +2,35 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { blocks } = mempoolJS(); const {
liquid: { blocks },
} = mempoolJS();
const hash = const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock(hash); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus(hash); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids(hash); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw(hash); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight(9999); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight); console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });

View File

@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
liquid: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://mempool.space/mempool.js"></script>
<script>
const init = async () => {
const {
liquid: { mempool },
} = mempoolJS();
const getMempool = await mempool.getMempool();
console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids);
};
init();
</script>
</head>
<body></body>
</html>

View File

@@ -2,35 +2,34 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { transactions } = mempoolJS(); const {
liquid: { transactions },
} = mempoolJS();
const txid = const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521'; '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx(txid); const tx = await transactions.getTx({ txid });
console.log(tx); console.log(tx);
const txStatus = await transactions.getTxStatus(txid); const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus); console.log(txStatus);
const txHex = await transactions.getTxHex(txid); const txHex = await transactions.getTxHex({ txid });
console.log(txHex); console.log(txHex);
const txRaw = await transactions.getTxRaw(txid); const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw); console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof( const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({
txid txid,
); });
console.log(txMerkleBlockProof); console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof(txid); const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof); console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({ const txOutspend = await transactions.getTxOutspend({
@@ -39,10 +38,10 @@
}); });
console.log(txOutspend); console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends(txid); const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends); console.log(txOutspends);
// const postTx = await transactions.postTx(txid); // const postTx = await transactions.postTx({ txid });
// console.log(postTx); // console.log(postTx);
}; };
init(); init();

View File

@@ -2,24 +2,21 @@
<html> <html>
<head> <head>
<title>Page Title</title> <title>Page Title</title>
<script <script src="https://mempool.space/mempool.js"></script>
type="text/javascript"
src="https://mempool.space/mempool.js"
></script>
<script> <script>
const init = async () => { const init = async () => {
const { websocket } = mempoolJS(); const {
liquid: { websocket },
} = mempoolJS();
const ws = await websocket.initClient({ const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
}); });
ws.addEventListener('message', function incoming({ data }) { ws.on('message', function incoming(data) {
const res = JSON.parse(data); const res = JSON.parse(data.toString());
if (res.blocks) { if (res.blocks) {
res.blocks.forEach((block) => { console.log(res.blocks);
console.log(block.height);
});
} }
if (res.mempoolInfo) { if (res.mempoolInfo) {
console.log(res.mempoolInfo); console.log(res.mempoolInfo);

View File

@@ -1,23 +0,0 @@
import mempoolJS from '../../src/index';
const init = async () => {
const { addresses } = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const addressTest = await addresses.getAddress(address);
console.log(addressTest);
const addressTxs = await addresses.getAddressTxs(address);
console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain(address);
console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool(address);
console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo(address);
console.log(addressTxsUtxo);
};
init();

View File

@@ -0,0 +1,13 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { addresses },
} = mempoolJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
};
init();

View File

@@ -0,0 +1,23 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { blocks },
} = mempoolJS();
const hash =
'000000000000000000079aa6bfa46eb8fc20474e8673d6e8a123b211236bf82d';
const block = await blocks.getBlock({ hash });
console.log(block);
const myBlocks = await blocks.getBlocks({ index: 0, length: 1 });
console.log(myBlocks);
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
};
init();

View File

@@ -0,0 +1,11 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { statistics },
} = mempoolJS();
const stats = await statistics.getStats();
console.log(stats);
};
init();

View File

@@ -0,0 +1,17 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bisq: { transactions },
} = mempoolJS();
const txid =
'4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
};
init();

View File

@@ -0,0 +1,25 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bitcoin: { addresses },
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo);
};
init();

View File

@@ -0,0 +1,41 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bitcoin: { blocks },
} = mempoolJS();
const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock({ hash });
console.log(block);
const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 });
console.log(getBlocks);
const blocksTipHeight = await blocks.getBlocksTipHeight();
console.log(blocksTipHeight);
const blocksTipHash = await blocks.getBlocksTipHash();
console.log(blocksTipHash);
};
init();

View File

@@ -0,0 +1,19 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bitcoin: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks);
const txid = 'txid';
const feesCPFP = await fees.getCPFP({ txid });
console.log(feesCPFP);
};
init();

View File

@@ -0,0 +1,17 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bitcoin: { mempool },
} = mempoolJS();
const getMempool = await mempool.getMempool();
console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids);
};
init();

View File

@@ -0,0 +1,41 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
bitcoin: { transactions },
} = mempoolJS();
const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus);
const txHex = await transactions.getTxHex({ txid });
console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({
txid,
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends);
// const postTx = await transactions.postTx({ txid });
// console.log(postTx);
};
init();

View File

@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ import mempoolJS from '../../../src/index';
import mempoolJS from '../../src/index';
const init = async () => { const init = async () => {
const { websocket } = mempoolJS(); const {
bitcoin: { websocket },
} = mempoolJS();
const ws = websocket.initServer({ const ws = websocket.initServer({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'], options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
@@ -11,9 +12,7 @@ const init = async () => {
ws.on('message', function incoming(data) { ws.on('message', function incoming(data) {
const res = JSON.parse(data.toString()); const res = JSON.parse(data.toString());
if (res.blocks) { if (res.blocks) {
res.blocks.forEach((block: { height: any }) => { console.log(res.blocks);
console.log(block.height);
});
} }
if (res.mempoolInfo) { if (res.mempoolInfo) {
console.log(res.mempoolInfo); console.log(res.mempoolInfo);

View File

@@ -0,0 +1,25 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
liquid: { addresses },
} = mempoolJS();
const address = '1wizSAYSbuyXbt9d8JV8ytm5acqq2TorC';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
const addressTxs = await addresses.getAddressTxs({ address });
console.log(addressTxs);
const addressTxsChain = await addresses.getAddressTxsChain({ address });
console.log(addressTxsChain);
const addressTxsMempool = await addresses.getAddressTxsMempool({ address });
console.log(addressTxsMempool);
const addressTxsUtxo = await addresses.getAddressTxsUtxo({ address });
console.log(addressTxsUtxo);
};
init();

View File

@@ -0,0 +1,20 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
liquid: { assets },
} = mempoolJS();
const asset_id =
'6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d';
const asset = await assets.getAsset({ asset_id });
console.log(asset);
const assetTxs = await assets.getAssetTxs({ asset_id, is_mempool: false });
console.log(assetTxs);
const assetSupply = await assets.getAssetSupply({ asset_id, decimal: false });
console.log(assetSupply);
};
init();

View File

@@ -1,30 +1,32 @@
import mempoolJS from '../../src/index'; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
const { blocks } = mempoolJS(); const {
liquid: { blocks },
} = mempoolJS();
const hash = const hash =
'000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce'; '000000000000000015dc777b3ff2611091336355d3f0ee9766a2cf3be8e4b1ce';
const block = await blocks.getBlock(hash); const block = await blocks.getBlock({ hash });
console.log(block); console.log(block);
const blockStatus = await blocks.getBlockStatus(hash); const blockStatus = await blocks.getBlockStatus({ hash });
console.log(blockStatus); console.log(blockStatus);
const blockTxs = await blocks.getBlockTxs({ hash }); const blockTxs = await blocks.getBlockTxs({ hash });
console.log(blockTxs); console.log(blockTxs);
const blockTxids = await blocks.getBlockTxids(hash); const blockTxids = await blocks.getBlockTxids({ hash });
console.log(blockTxids); console.log(blockTxids);
const blockTxid = await blocks.getBlockTxid({ hash, index: 218 }); const blockTxid = await blocks.getBlockTxid({ hash, index: 218 });
console.log(blockTxid); console.log(blockTxid);
const blockRaw = await blocks.getBlockRaw(hash); const blockRaw = await blocks.getBlockRaw({ hash });
console.log(blockRaw); console.log(blockRaw);
const blockHeight = await blocks.getBlockHeight(9999); const blockHeight = await blocks.getBlockHeight({ height: 0 });
console.log(blockHeight); console.log(blockHeight);
const getBlocks = await blocks.getBlocks({ start_height: 9999 }); const getBlocks = await blocks.getBlocks({ start_height: 9999 });

View File

@@ -1,7 +1,9 @@
import mempoolJS from '../../src/index'; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
const { fees } = mempoolJS(); const {
liquid: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended(); const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended); console.log(feesRecommended);

View File

@@ -1,7 +1,9 @@
import mempoolJS from '../../src/index'; import mempoolJS from '../../../src/index';
const init = async () => { const init = async () => {
const { mempool } = mempoolJS(); const {
liquid: { mempool },
} = mempoolJS();
const getMempool = await mempool.getMempool(); const getMempool = await mempool.getMempool();
console.log(getMempool); console.log(getMempool);

View File

@@ -0,0 +1,41 @@
import mempoolJS from '../../../src/index';
const init = async () => {
const {
liquid: { transactions },
} = mempoolJS();
const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txStatus = await transactions.getTxStatus({ txid });
console.log(txStatus);
const txHex = await transactions.getTxHex({ txid });
console.log(txHex);
const txRaw = await transactions.getTxRaw({ txid });
console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof({ txid });
console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({
txid,
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends({ txid });
console.log(txOutspends);
// const postTx = await transactions.postTx({ txid });
// console.log(postTx);
};
init();

View File

@@ -0,0 +1,28 @@
import mempoolJS from '../../../src/index';
const init = async () => {
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);
}
});
};
init();

View File

@@ -1,39 +0,0 @@
import mempoolJS from '../../src/index';
const init = async () => {
const { transactions } = mempoolJS();
const txid =
'15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const tx = await transactions.getTx(txid);
console.log(tx);
const txStatus = await transactions.getTxStatus(txid);
console.log(txStatus);
const txHex = await transactions.getTxHex(txid);
console.log(txHex);
const txRaw = await transactions.getTxRaw(txid);
console.log(txRaw);
const txMerkleBlockProof = await transactions.getTxMerkleBlockProof(txid);
console.log(txMerkleBlockProof);
const txMerkleProof = await transactions.getTxMerkleProof(txid);
console.log(txMerkleProof);
const txOutspend = await transactions.getTxOutspend({
txid,
vout: 3,
});
console.log(txOutspend);
const txOutspends = await transactions.getTxOutspends(txid);
console.log(txOutspends);
// const postTx = await transactions.postTx(txid);
// console.log(postTx);
};
init();

View File

@@ -1,39 +0,0 @@
import { AxiosInstance } from 'axios';
import { Address, AddressTxsUtxo, Tx, AddressInstance } from '../interfaces';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (address: string) => {
const { data } = await api.get<Address>(`/address/${address}`);
return data;
};
const getAddressTxs = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs`);
return data;
};
const getAddressTxsChain = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs/chain`);
return data;
};
const getAddressTxsMempool = async (address: string) => {
const { data } = await api.get<Tx[]>(`/address/${address}/txs/mempool`);
return data;
};
const getAddressTxsUtxo = async (address: string) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

13
src/app/bisq/addresses.ts Normal file
View File

@@ -0,0 +1,13 @@
import { AxiosInstance } from 'axios';
import { Address, AddressesInstance } from '../../interfaces/bisq/addresses';
export const useAddresses = (api: AxiosInstance): AddressesInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/block/${params.address}`);
return data;
};
return {
getAddress,
};
};

27
src/app/bisq/blocks.ts Normal file
View File

@@ -0,0 +1,27 @@
import { AxiosInstance } from 'axios';
import { Block, BlocksInstance } from '../../interfaces/bisq/blocks';
export const useBlocks = (api: AxiosInstance): BlocksInstance => {
const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${params.hash}`);
return data;
};
const getBlocks = async (params: { index: number; length: number }) => {
const { data } = await api.get<Block>(
`/blocks/${params.index}/${params.length}`
);
return data;
};
const getBlocksTipHeight = async () => {
const { data } = await api.get<number>(`/blocks/tip/height`);
return data;
};
return {
getBlock,
getBlocks,
getBlocksTipHeight,
};
};

View File

@@ -0,0 +1,13 @@
import { AxiosInstance } from 'axios';
import { Stats, StatsInstance } from '../../interfaces/bisq/statistics';
export const useStatistics = (api: AxiosInstance): StatsInstance => {
const getStats = async () => {
const { data } = await api.get<Stats>(`/stats`);
return data;
};
return {
getStats,
};
};

View File

@@ -0,0 +1,21 @@
import { AxiosInstance } from 'axios';
import { Tx, TransactionsInstance } from '../../interfaces/bisq/transactions';
export const useTransactions = (api: AxiosInstance): TransactionsInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxs = async (params: { index: number; length: number }) => {
const { data } = await api.get<Tx[]>(
`/txs/${params.index}/${params.length}`
);
return data;
};
return {
getTx,
getTxs,
};
};

View File

@@ -0,0 +1,48 @@
import { AxiosInstance } from 'axios';
import {
Address,
AddressTxsUtxo,
AddressInstance,
} from '../../interfaces/bitcoin/addresses';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/address/${params.address}`);
return data;
};
const getAddressTxs = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data;
};
const getAddressTxsChain = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/chain`
);
return data;
};
const getAddressTxsMempool = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/mempool`
);
return data;
};
const getAddressTxsUtxo = async (params: { address: string }) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${params.address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

View File

@@ -1,14 +1,19 @@
import { AxiosInstance } from 'axios'; import { AxiosInstance } from 'axios';
import { Block, BlockStatus, BlockInstance, Tx } from '../interfaces'; import {
Block,
BlockStatus,
BlockInstance,
} from '../../interfaces/bitcoin/blocks';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockInstance => { export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (hash: string) => { const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${hash}`); const { data } = await api.get<Block>(`/block/${params.hash}`);
return data; return data;
}; };
const getBlockStatus = async (hash: string) => { const getBlockStatus = async (params: { hash: string }) => {
const { data } = await api.get<BlockStatus>(`/block/${hash}/status`); const { data } = await api.get<BlockStatus>(`/block/${params.hash}/status`);
return data; return data;
}; };
@@ -22,8 +27,8 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
return data; return data;
}; };
const getBlockTxids = async (hash: string) => { const getBlockTxids = async (params: { hash: string }) => {
const { data } = await api.get<string[]>(`/block/${hash}/txids`); const { data } = await api.get<string[]>(`/block/${params.hash}/txids`);
return data; return data;
}; };
@@ -34,13 +39,13 @@ export const useBlocks = (api: AxiosInstance): BlockInstance => {
return data; return data;
}; };
const getBlockRaw = async (hash: string) => { const getBlockRaw = async (params: { hash: string }) => {
const { data } = await api.get<string>(`/block/${hash}/raw`); const { data } = await api.get<string>(`/block/${params.hash}/raw`);
return data; return data;
}; };
const getBlockHeight = async (height: number) => { const getBlockHeight = async (params: { height: number }) => {
const { data } = await api.get<string>(`/block-height/${height}`); const { data } = await api.get<string>(`/block-height/${params.height}`);
return data; return data;
}; };

View File

@@ -1,5 +1,9 @@
import { AxiosInstance } from 'axios'; import { AxiosInstance } from 'axios';
import { FeesRecommended, FeesMempoolBlocks, FeeInstance } from '../interfaces'; import {
FeesRecommended,
FeesMempoolBlocks,
FeeInstance,
} from '../../interfaces/bitcoin/fees';
export const useFees = (api: AxiosInstance): FeeInstance => { export const useFees = (api: AxiosInstance): FeeInstance => {
const getFeesRecommended = async () => { const getFeesRecommended = async () => {
@@ -14,8 +18,16 @@ export const useFees = (api: AxiosInstance): FeeInstance => {
return data; return data;
}; };
const getCPFP = async (params: { txid: string }) => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/cpfp/${params.txid}`
);
return data;
};
return { return {
getFeesRecommended, getFeesRecommended,
getFeesMempoolBlocks, getFeesMempoolBlocks,
getCPFP,
}; };
}; };

View File

@@ -1,5 +1,9 @@
import { AxiosInstance } from 'axios'; import { AxiosInstance } from 'axios';
import { Mempool, MempoolRecent, MempoolInstance } from '../interfaces'; import {
Mempool,
MempoolRecent,
MempoolInstance,
} from '../../interfaces/bitcoin/mempool';
export const useMempool = (api: AxiosInstance): MempoolInstance => { export const useMempool = (api: AxiosInstance): MempoolInstance => {
const getMempool = async () => { const getMempool = async () => {

View File

@@ -0,0 +1,75 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../../interfaces/bitcoin/transactions';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxStatus = async (params: { txid: string }) => {
const { data } = await api.get<TxStatus>(`/tx/${params.txid}/status`);
return data;
};
const getTxHex = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/hex`);
return data;
};
const getTxRaw = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (params: { txid: string }) => {
const { data } = await api.get<string>(
`/tx/${params.txid}/merkleblock-proof`
);
return data;
};
const getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxOutspend>>(
`/tx/${params.txid}/outspends`
);
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -0,0 +1,14 @@
import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import wsClient from '../../services/ws/client';
import wsServer from '../../services/ws/server';
const defaultWs = 'wss://mempool.space/api/v1/ws';
export const useWebsocket = (hostname?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, hostname),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, hostname),
};
};

View File

@@ -0,0 +1,48 @@
import { AxiosInstance } from 'axios';
import {
Address,
AddressTxsUtxo,
AddressInstance,
} from '../../interfaces/bitcoin/addresses';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useAddresses = (api: AxiosInstance): AddressInstance => {
const getAddress = async (params: { address: string }) => {
const { data } = await api.get<Address>(`/address/${params.address}`);
return data;
};
const getAddressTxs = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(`/address/${params.address}/txs`);
return data;
};
const getAddressTxsChain = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/chain`
);
return data;
};
const getAddressTxsMempool = async (params: { address: string }) => {
const { data } = await api.get<Tx[]>(
`/address/${params.address}/txs/mempool`
);
return data;
};
const getAddressTxsUtxo = async (params: { address: string }) => {
const { data } = await api.get<AddressTxsUtxo[]>(
`/address/${params.address}/utxo`
);
return data;
};
return {
getAddress,
getAddressTxs,
getAddressTxsChain,
getAddressTxsMempool,
getAddressTxsUtxo,
};
};

37
src/app/liquid/assets.ts Normal file
View File

@@ -0,0 +1,37 @@
import { AxiosInstance } from 'axios';
import { Asset, AssetsInstance } from '../../interfaces/liquid/assets';
export const useAssets = (api: AxiosInstance): AssetsInstance => {
const getAsset = async (params: { asset_id: string }) => {
const { data } = await api.get<Asset>(`/asset/${params.asset_id}`);
return data;
};
const getAssetTxs = async (params: {
asset_id: string;
is_mempool: boolean;
}) => {
const paramsMempools = params.is_mempool === true ? '/mempool' : '/chain';
const { data } = await api.get<Asset>(
`/asset/${params.asset_id}/txs${paramsMempools}`
);
return data;
};
const getAssetSupply = async (params: {
asset_id: string;
decimal: boolean;
}) => {
const paramDecimal = params.decimal === true ? '/decimal' : '';
const { data } = await api.get<Asset>(
`/asset/${params.asset_id}/supply${paramDecimal}`
);
return data;
};
return {
getAsset,
getAssetTxs,
getAssetSupply,
};
};

79
src/app/liquid/blocks.ts Normal file
View File

@@ -0,0 +1,79 @@
import { AxiosInstance } from 'axios';
import {
Block,
BlockStatus,
BlockInstance,
} from '../../interfaces/bitcoin/blocks';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockInstance => {
const getBlock = async (params: { hash: string }) => {
const { data } = await api.get<Block>(`/block/${params.hash}`);
return data;
};
const getBlockStatus = async (params: { hash: string }) => {
const { data } = await api.get<BlockStatus>(`/block/${params.hash}/status`);
return data;
};
const getBlockTxs = async (params: {
hash: string;
start_index?: number;
}) => {
const { data } = await api.get<Tx>(
`/block/${params.hash}/txs/${params.start_index}`
);
return data;
};
const getBlockTxids = async (params: { hash: string }) => {
const { data } = await api.get<string[]>(`/block/${params.hash}/txids`);
return data;
};
const getBlockTxid = async (params: { hash: string; index: number }) => {
const { data } = await api.get<string>(
`/block/${params.hash}/txid/${params.index}`
);
return data;
};
const getBlockRaw = async (params: { hash: string }) => {
const { data } = await api.get<string>(`/block/${params.hash}/raw`);
return data;
};
const getBlockHeight = async (params: { height: number }) => {
const { data } = await api.get<string>(`/block-height/${params.height}`);
return data;
};
const getBlocks = async (params: { start_height?: number }) => {
const { data } = await api.get<Block>(`/blocks/${params.start_height}`);
return data;
};
const getBlocksTipHeight = async () => {
const { data } = await api.get<number>(`/blocks/tip/height`);
return data;
};
const getBlocksTipHash = async () => {
const { data } = await api.get<string>(`/blocks/tip/hash`);
return data;
};
return {
getBlock,
getBlocks,
getBlockStatus,
getBlockTxs,
getBlockTxid,
getBlockTxids,
getBlockRaw,
getBlockHeight,
getBlocksTipHash,
getBlocksTipHeight,
};
};

33
src/app/liquid/fees.ts Normal file
View File

@@ -0,0 +1,33 @@
import { AxiosInstance } from 'axios';
import {
FeesRecommended,
FeesMempoolBlocks,
FeeInstance,
} from '../../interfaces/bitcoin/fees';
export const useFees = (api: AxiosInstance): FeeInstance => {
const getFeesRecommended = async () => {
const { data } = await api.get<FeesRecommended>(`/v1/fees/recommended`);
return data;
};
const getFeesMempoolBlocks = async () => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/fees/mempool-blocks`
);
return data;
};
const getCPFP = async (params: { txid: string }) => {
const { data } = await api.get<FeesMempoolBlocks[]>(
`/v1/cpfp/${params.txid}`
);
return data;
};
return {
getFeesRecommended,
getFeesMempoolBlocks,
getCPFP,
};
};

29
src/app/liquid/mempool.ts Normal file
View File

@@ -0,0 +1,29 @@
import { AxiosInstance } from 'axios';
import {
Mempool,
MempoolRecent,
MempoolInstance,
} from '../../interfaces/bitcoin/mempool';
export const useMempool = (api: AxiosInstance): MempoolInstance => {
const getMempool = async () => {
const { data } = await api.get<Mempool[]>(`/mempool`);
return data;
};
const getMempoolTxids = async () => {
const { data } = await api.get<string[]>(`/mempool/txids`);
return data;
};
const getMempoolRecent = async () => {
const { data } = await api.get<MempoolRecent[]>(`/mempool/recent`);
return data;
};
return {
getMempool,
getMempoolTxids,
getMempoolRecent,
};
};

View File

@@ -0,0 +1,75 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../../interfaces/bitcoin/transactions';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (params: { txid: string }) => {
const { data } = await api.get<Tx>(`/tx/${params.txid}`);
return data;
};
const getTxStatus = async (params: { txid: string }) => {
const { data } = await api.get<TxStatus>(`/tx/${params.txid}/status`);
return data;
};
const getTxHex = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/hex`);
return data;
};
const getTxRaw = async (params: { txid: string }) => {
const { data } = await api.get<string>(`/tx/${params.txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (params: { txid: string }) => {
const { data } = await api.get<string>(
`/tx/${params.txid}/merkleblock-proof`
);
return data;
};
const getTxMerkleProof = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${params.txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (params: { txid: string }) => {
const { data } = await api.get<Array<TxOutspend>>(
`/tx/${params.txid}/outspends`
);
return data;
};
const postTx = async (params: { txid: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -0,0 +1,14 @@
import { WsInterface, WsInstance } from '../../interfaces/bitcoin/websockets';
import wsClient from '../../services/ws/client';
import wsServer from '../../services/ws/server';
const defaultWs = 'wss://mempool.space/liquid/api/v1/ws';
export const useWebsocket = (hostname?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, hostname),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, hostname),
};
};

View File

@@ -1,71 +0,0 @@
import { AxiosInstance } from 'axios';
import {
Tx,
TxStatus,
TxMerkleProof,
TxOutspend,
TxInstance,
} from '../interfaces';
export const useTransactions = (api: AxiosInstance): TxInstance => {
const getTx = async (txid: string) => {
const { data } = await api.get<Tx>(`/tx/${txid}`);
return data;
};
const getTxStatus = async (txid: string) => {
const { data } = await api.get<TxStatus>(`/tx/${txid}/status`);
return data;
};
const getTxHex = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/hex`);
return data;
};
const getTxRaw = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/raw`);
return data;
};
const getTxMerkleBlockProof = async (txid: string) => {
const { data } = await api.get<string>(`/tx/${txid}/merkleblock-proof`);
return data;
};
const getTxMerkleProof = async (txid: string) => {
const { data } = await api.get<Array<TxMerkleProof>>(
`/tx/${txid}/merkle-proof`
);
return data;
};
const getTxOutspend = async (params: { txid: string; vout: number }) => {
const { data } = await api.get<TxOutspend>(
`/tx/${params.txid}/outspend/${params.vout}`
);
return data;
};
const getTxOutspends = async (txid: string) => {
const { data } = await api.get<Array<TxOutspend>>(`/tx/${txid}/outspends`);
return data;
};
const postTx = async (txid: string) => {
const { data } = await api.post<string>(`/tx`, { txid: txid });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

View File

@@ -1,14 +0,0 @@
import { WsInterface, WsInstance } from '../interfaces';
import wsClient from '../services/wsClient';
import wsServer from '../services/wsServer';
const defaultWs = 'wss://mempool.space/api/v1/ws';
export const useWebsocket = (websocketEndpoint?: string): WsInstance => {
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, defaultWs, websocketEndpoint),
initServer: ({ options }: WsInterface) =>
wsServer(options, defaultWs, websocketEndpoint),
};
};

View File

@@ -1,31 +1,70 @@
import { MempoolConfig, MempoolReturn } from './interfaces'; import { MempoolConfig, MempoolReturn } from './interfaces/index';
import { makeAPI } from './services/api'; import {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
} from './services/api/index';
import { useAddresses } from './app/addresses'; import { useAddresses } from './app/bitcoin/addresses';
import { useBlocks } from './app/blocks'; import { useBlocks } from './app/bitcoin/blocks';
import { useFees } from './app/fees'; import { useFees } from './app/bitcoin/fees';
import { useMempool } from './app/mempool'; import { useMempool } from './app/bitcoin/mempool';
import { useTransactions } from './app/transactions'; import { useTransactions } from './app/bitcoin/transactions';
import { useWebsocket } from './app/websocket'; import { useWebsocket } from './app/bitcoin/websocket';
const apiEndpointDefault = 'https://mempool.space/api/'; import { useAddresses as useAddressesBisq } from './app/bisq/addresses';
const websocketEndpointDefault = 'wss://mempool.space/api/v1/ws'; import { useBlocks as useBlocksBisq } from './app/bisq/blocks';
import { useStatistics as useStatisticsBisq } from './app/bisq/statistics';
import { useTransactions as useTransactionsBisq } from './app/bisq/transactions';
import { useAssets as useAssetsLiquid } from './app/liquid/assets';
import { useAddresses as useAddressesLiquid } from './app/liquid/addresses';
import { useBlocks as useBlocksLiquid } from './app/liquid/blocks';
import { useFees as useFeesLiquid } from './app/liquid/fees';
import { useMempool as useMempoolLiquid } from './app/liquid/mempool';
import { useTransactions as useTransactionsLiquid } from './app/liquid/transactions';
import { useWebsocket as useWebsocketLiquid } from './app/liquid/websocket';
const hostnameEndpointDefault = 'mempool.space';
const networkEndpointDefault = 'main';
const mempool = ( const mempool = (
{ apiEndpoint, websocketEndpoint }: MempoolConfig = { { hostname, network }: MempoolConfig = {
apiEndpoint: apiEndpointDefault, hostname: hostnameEndpointDefault,
websocketEndpoint: websocketEndpointDefault, network: networkEndpointDefault,
} }
): MempoolReturn => { ): MempoolReturn => {
const { api } = makeAPI(apiEndpoint); if (!hostname) hostname = hostnameEndpointDefault;
if (!network) network = networkEndpointDefault;
const { api: apiBitcoin } = makeBitcoinAPI({ hostname, network });
const { api: apiBisq } = makeBisqAPI(hostname);
const { api: apiLiquid } = makeLiquidAPI(hostname);
return { return {
addresses: useAddresses(api), bitcoin: {
blocks: useBlocks(api), addresses: useAddresses(apiBitcoin),
fees: useFees(api), blocks: useBlocks(apiBitcoin),
mempool: useMempool(api), fees: useFees(apiBitcoin),
transactions: useTransactions(api), mempool: useMempool(apiBitcoin),
websocket: useWebsocket(websocketEndpoint), transactions: useTransactions(apiBitcoin),
websocket: useWebsocket(hostname),
},
bisq: {
statistics: useStatisticsBisq(apiBisq),
addresses: useAddressesBisq(apiBisq),
blocks: useBlocksBisq(apiBisq),
transactions: useTransactionsBisq(apiBisq),
},
liquid: {
addresses: useAddressesLiquid(apiLiquid),
assets: useAssetsLiquid(apiLiquid),
blocks: useBlocksLiquid(apiLiquid),
fees: useFeesLiquid(apiLiquid),
mempool: useMempoolLiquid(apiLiquid),
transactions: useTransactionsLiquid(apiLiquid),
websocket: useWebsocketLiquid(hostname),
},
}; };
}; };

View File

@@ -1,213 +0,0 @@
import WebSocketServer from 'ws';
export interface Address {
address: string;
chain_stats: {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
};
mempool_stats: {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
};
}
export interface AddressInstance {
getAddress: (address: string) => Promise<Address>;
getAddressTxs: (address: string) => Promise<Tx[]>;
getAddressTxsChain: (address: string) => Promise<Tx[]>;
getAddressTxsMempool: (address: string) => Promise<Tx[]>;
getAddressTxsUtxo: (address: string) => Promise<AddressTxsUtxo[]>;
}
export interface AddressTxsUtxo {
txid: string;
vout: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
value: number;
}
export interface Block {
id: string;
height: number;
version: number;
timestamp: number;
tx_count: number;
size: number;
weight: number;
merkle_root: string;
previousblockhash: string;
mediantime: number;
nonce: number;
bits: number;
difficulty: number;
}
export interface BlockInstance {
getBlock: (hash: string) => Promise<Block>;
getBlocks: (params: { start_height?: number }) => Promise<Block>;
getBlockStatus: (hash: string) => Promise<BlockStatus>;
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
getBlockTxids: (hash: string) => Promise<string[]>;
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
getBlockRaw: (hash: string) => Promise<string>;
getBlockHeight: (height: number) => Promise<string>;
getBlocksTipHeight: () => Promise<number>;
getBlocksTipHash: () => Promise<string>;
}
export interface BlockStatus {
in_best_chain: boolean;
height: number;
next_best: string;
}
export interface FeeInstance {
getFeesRecommended: () => Promise<FeesRecommended>;
getFeesMempoolBlocks: () => Promise<FeesMempoolBlocks[]>;
}
export interface FeesMempoolBlocks {
blockSize: number;
blockVSize: number;
nTx: number;
totalFees: number;
medianFee: number;
feeRange: number[];
}
export interface FeesRecommended {
fastestFee: number;
halfHourFee: number;
hourFee: number;
minimumFee: number;
}
export interface Mempool {
count: number;
vsize: number;
total_fee: number;
fee_histogram: number[];
}
export interface MempoolConfig {
apiEndpoint?: string;
websocketEndpoint?: string;
}
export interface MempoolInstance {
getMempool: () => Promise<Mempool[]>;
getMempoolTxids: () => Promise<string[]>;
getMempoolRecent: () => Promise<MempoolRecent[]>;
}
export interface MempoolReturn {
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
}
export interface MempoolRecent {
txid: string;
fee: number;
vsize: number;
value: number;
}
export interface Tx {
txid: string;
version: number;
locktime: number;
vin: {
txid: string;
vout: number;
prevout: {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
};
scriptsig: string;
scriptsig_asm: string;
is_coinbase: boolean;
sequence: string;
}[];
vout: {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
}[];
size: number;
weight: number;
fee: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
}
export interface TxStatus {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
}
export interface TxMerkleProof {
block_height: number;
merkle: string[];
pos: number;
}
export interface TxOutspend {
spent: boolean;
txid: string;
vin: number;
status: {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
};
}
export interface TxInstance {
getTx: (txid: string) => Promise<Tx>;
getTxStatus: (txid: string) => Promise<TxStatus>;
getTxHex: (txid: string) => Promise<string>;
getTxRaw: (txid: string) => Promise<string>;
getTxMerkleBlockProof: (txid: string) => Promise<string>;
getTxMerkleProof: (txid: string) => Promise<Array<TxMerkleProof>>;
getTxOutspend: (params: {
txid: string;
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (txid: string) => Promise<Array<TxOutspend>>;
postTx: (txid: string) => Promise<unknown>;
}
export interface WsInterface {
options: string[];
}
export interface WsInstance {
initClient: ({ options }: WsInterface) => WebSocket;
initServer: ({ options }: WsInterface) => WebSocketServer;
}

View File

@@ -0,0 +1,13 @@
import { Tx } from './transactions';
export interface Address {
height: number;
time: number;
hash: string;
previousBlockHash: string;
txs: Tx[];
}
export interface AddressesInstance {
getAddress: (params: { address: string }) => Promise<Address>;
}

View File

@@ -0,0 +1,18 @@
import { Tx } from './transactions';
export interface Block {
height: number;
time: number;
hash: string;
previousBlockHash: string;
txs: Tx[];
}
export interface BlocksInstance {
getBlock: (params: { hash: string }) => Promise<Block>;
getBlocks: (params: { index: number; length: number }) => Promise<Block>;
getBlocksTipHeight: (params: {
index: number;
length: number;
}) => Promise<number>;
}

View File

@@ -0,0 +1,11 @@
export interface Stats {
address: number;
minted: number;
burnt: number;
spent_txos: number;
unspent_txos: number;
}
export interface StatsInstance {
getStats: () => Promise<Stats>;
}

View File

@@ -0,0 +1,46 @@
export interface Tx {
txVersion: string;
id: string;
blockHeight: number;
blockHash: string;
time: number;
inputs: [];
outputs: [
{
txVersion: string;
txId: string;
index: number;
bsqAmount: number;
btcAmount: number;
height: number;
isVerified: true;
burntFee: number;
invalidatedBsq: number;
address: string;
scriptPubKey: {
addresses: [string];
asm: string;
hex: string;
reqSigs: number;
type: string;
};
time: number;
txType: string;
txTypeDisplayString: string;
txOutputType: string;
txOutputTypeDisplayString: string;
lockTime: number;
isUnspent: true;
}
];
txType: string;
txTypeDisplayString: string;
burntFee: number;
invalidatedBsq: number;
unlockBlockHeight: number;
}
export interface TransactionsInstance {
getTx: (params: { txid: string }) => Promise<Tx>;
getTxs: (params: { index: number; length: number }) => Promise<Tx[]>;
}

View File

@@ -0,0 +1,30 @@
import { Tx, TxStatus } from './transactions';
export interface Address {
address: string;
chain_stats: StatsInfo;
mempool_stats: StatsInfo;
}
export interface StatsInfo {
funded_txo_count: number;
funded_txo_sum: number;
spent_txo_count: number;
spent_txo_sum: number;
tx_count: number;
}
export interface AddressTxsUtxo {
txid: string;
vout: number;
status: TxStatus;
value: number;
}
export interface AddressInstance {
getAddress: (params: { address: string }) => Promise<Address>;
getAddressTxs: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsChain: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsMempool: (params: { address: string }) => Promise<Tx[]>;
getAddressTxsUtxo: (params: { address: string }) => Promise<AddressTxsUtxo[]>;
}

View File

@@ -0,0 +1,36 @@
import { Tx } from './transactions';
export interface Block {
id: string;
height: number;
version: number;
timestamp: number;
tx_count: number;
size: number;
weight: number;
merkle_root: string;
previousblockhash: string;
mediantime: number;
nonce: number;
bits: number;
difficulty: number;
}
export interface BlockStatus {
in_best_chain: boolean;
height: number;
next_best: string;
}
export interface BlockInstance {
getBlock: (params: { hash: string }) => Promise<Block>;
getBlocks: (params: { start_height?: number }) => Promise<Block>;
getBlockStatus: (params: { hash: string }) => Promise<BlockStatus>;
getBlockTxs: (params: { hash: string; start_index?: number }) => Promise<Tx>;
getBlockTxids: (params: { hash: string }) => Promise<string[]>;
getBlockTxid: (params: { hash: string; index: number }) => Promise<string>;
getBlockRaw: (params: { hash: string }) => Promise<string>;
getBlockHeight: (params: { height: number }) => Promise<string>;
getBlocksTipHeight: () => Promise<number>;
getBlocksTipHash: () => Promise<string>;
}

View File

@@ -0,0 +1,21 @@
export interface FeesMempoolBlocks {
blockSize: number;
blockVSize: number;
nTx: number;
totalFees: number;
medianFee: number;
feeRange: number[];
}
export interface FeesRecommended {
fastestFee: number;
halfHourFee: number;
hourFee: number;
minimumFee: number;
}
export interface FeeInstance {
getFeesRecommended: () => Promise<FeesRecommended>;
getFeesMempoolBlocks: () => Promise<FeesMempoolBlocks[]>;
getCPFP: (params: { txid: string }) => Promise<FeesMempoolBlocks[]>;
}

View File

@@ -0,0 +1,19 @@
export interface Mempool {
count: number;
vsize: number;
total_fee: number;
fee_histogram: number[];
}
export interface MempoolInstance {
getMempool: () => Promise<Mempool[]>;
getMempoolTxids: () => Promise<string[]>;
getMempoolRecent: () => Promise<MempoolRecent[]>;
}
export interface MempoolRecent {
txid: string;
fee: number;
vsize: number;
value: number;
}

View File

@@ -0,0 +1,62 @@
export interface Tx {
txid: string;
version: number;
locktime: number;
vin: {
txid: string;
vout: number;
prevout: Vout;
scriptsig: string;
scriptsig_asm: string;
is_coinbase: boolean;
sequence: string;
}[];
vout: Vout[];
size: number;
weight: number;
fee: number;
status: TxStatus;
}
export interface Vout {
scriptpubkey: string;
scriptpubkey_asm: string;
scriptpubkey_type: string;
scriptpubkey_address: string;
value: number;
}
export interface TxStatus {
confirmed: boolean;
block_height: number;
block_hash: string;
block_time: number;
}
export interface TxMerkleProof {
block_height: number;
merkle: string[];
pos: number;
}
export interface TxOutspend {
spent: boolean;
txid: string;
vin: number;
status: TxStatus;
}
export interface TxInstance {
getTx: (params: { txid: string }) => Promise<Tx>;
getTxStatus: (params: { txid: string }) => Promise<TxStatus>;
getTxHex: (params: { txid: string }) => Promise<string>;
getTxRaw: (params: { txid: string }) => Promise<string>;
getTxMerkleBlockProof: (params: { txid: string }) => Promise<string>;
getTxMerkleProof: (params: { txid: string }) => Promise<Array<TxMerkleProof>>;
getTxOutspend: (params: {
txid: string;
vout: number;
}) => Promise<TxOutspend>;
getTxOutspends: (params: { txid: string }) => Promise<Array<TxOutspend>>;
postTx: (params: { txid: string }) => Promise<unknown>;
}

View File

@@ -0,0 +1,10 @@
export interface WsInterface {
options: string[];
}
import WebSocketServer from 'ws';
export interface WsInstance {
initClient: ({ options }: WsInterface) => WebSocket;
initServer: ({ options }: WsInterface) => WebSocketServer;
}

44
src/interfaces/index.ts Normal file
View File

@@ -0,0 +1,44 @@
import { AddressInstance } from './bitcoin/addresses';
import { BlockInstance } from './bitcoin/blocks';
import { FeeInstance } from './bitcoin/fees';
import { MempoolInstance } from './bitcoin/mempool';
import { TxInstance } from './bitcoin/transactions';
import { WsInstance } from './bitcoin/websockets';
import { AddressesInstance } from './bisq/addresses';
import { BlocksInstance } from './bisq/blocks';
import { StatsInstance } from './bisq/statistics';
import { TransactionsInstance } from './bisq/transactions';
import { AssetsInstance } from './liquid/assets';
export interface MempoolConfig {
hostname?: string;
network?: string;
}
export interface MempoolReturn {
bitcoin: {
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
};
bisq: {
addresses: AddressesInstance;
blocks: BlocksInstance;
statistics: StatsInstance;
transactions: TransactionsInstance;
};
liquid: {
assets: AssetsInstance;
addresses: AddressInstance;
blocks: BlockInstance;
fees: FeeInstance;
mempool: MempoolInstance;
transactions: TxInstance;
websocket: WsInstance;
};
}

View File

@@ -0,0 +1,27 @@
export interface Asset {
asset_id: string;
chain_stats: AssetStats;
mempool_stats: AssetStats;
}
interface AssetStats {
tx_count: number;
peg_in_count: number;
peg_in_amount: number;
peg_out_count: number;
peg_out_amount: number;
burn_count: number;
burned_amount: number;
}
export interface AssetsInstance {
getAsset: (params: { asset_id: string }) => Promise<Asset>;
getAssetTxs: (params: {
asset_id: string;
is_mempool: boolean;
}) => Promise<Asset>;
getAssetSupply: (params: {
asset_id: string;
decimal: boolean;
}) => Promise<Asset>;
}

View File

@@ -1,10 +0,0 @@
import axios, { AxiosInstance } from 'axios';
export const makeAPI = (apiEndpoint?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: apiEndpoint,
});
return {
api,
};
};

43
src/services/api/index.ts Normal file
View File

@@ -0,0 +1,43 @@
import axios, { AxiosInstance } from 'axios';
import { MempoolConfig } from './../../interfaces/index';
export const makeBitcoinAPI = ({
hostname,
network,
}: MempoolConfig): { api: AxiosInstance } => {
if (network && ['testnet', 'signet'].includes(network)) {
network = `/${network}`;
} else {
network = '';
}
const api = axios.create({
baseURL: `https://${hostname}${network}/api/`,
});
return {
api,
};
};
export const makeBisqAPI = (hostname?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://${hostname}/bisq/api/`,
});
return {
api,
};
};
export const makeLiquidAPI = (hostname?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: `https://${hostname}/liquid/api/`,
});
return {
api,
};
};
export default {
makeBitcoinAPI,
makeBisqAPI,
makeLiquidAPI,
};

View File

@@ -12,14 +12,12 @@ const browserWS = (
const handleMessage = (ws: WebSocket, options: string[]) => { const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' })); ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() { ws.send(
ws.send( JSON.stringify({
JSON.stringify({ action: 'want',
action: 'want', data: options,
data: options, })
}) );
);
}, 500);
}; };
export default browserWS; export default browserWS;

View File

@@ -14,13 +14,11 @@ const serverWS = (
const handleMessage = (ws: WebSocket, options: string[]) => { const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' })); ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() { ws.send(
ws.send( JSON.stringify({
JSON.stringify({ action: 'want',
action: 'want', data: options,
data: options, })
}) );
);
}, 500);
}; };
export default serverWS; export default serverWS;