Merge remote-tracking branch 'mempooljs/main' into wiz/subtree-merge-mempool.js-repo

This commit is contained in:
wiz 2022-01-29 08:02:10 +00:00
commit 139c621a90
No known key found for this signature in database
GPG Key ID: A394E332255A6173
124 changed files with 20800 additions and 0 deletions

12
mempool.js/.editorconfig Normal file
View File

@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

16
mempool.js/.eslintrc.js Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
};

6
mempool.js/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/node_modules
/lib
/dist/*
!.gitkeep
yarn-error.log

6
mempool.js/.prettierrc Normal file
View File

@ -0,0 +1,6 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"printWidth": 80
}

21
mempool.js/LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021 Miguel Medeiros
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

147
mempool.js/README-bisq.md Normal file
View File

@ -0,0 +1,147 @@
# mempool**JS** - Bisq API
Interface to access Bisq API.
[Back to home](./README.md)
---
## **Features**
- 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)
---
### **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);
```

View File

@ -0,0 +1,748 @@
# mempool**JS** - Bitcoin API
Interface to access Bitcoin `mainet`, `testnet`, `signet` APIs.
[Back to home](./README.md)
---
## **Features**
- 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 Header](#get-blocks-header)
- [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)
- Difficulty
- [Get Difficulty Adjustment](#get-difficulty-adjustment)
- 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/mempool-js/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/mempool-js/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/mempool-js/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/mempool-js/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/mempool-js/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/mempool-js/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/mempool-js/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/mempool-js/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/mempool-js/bitcoin/addresses.ts) ] [ [HTML Example](examples/html/mempool-js/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 Header**
Returns the hex-encoded block header.
**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 blockHeader = await blocks.getBlockHeader({ hash: '0000000000000000000065bda8f8a88f2e1e00d9a6887a43d640e52a4c7660f2' });
console.log(blockHeader);
```
### **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 Difficulty Adjustment**
Returns the hash of the last block.
[ [NodeJS Example](examples/nodejs/bitcoin/difficulty.ts) ] [ [HTML Example](examples/html/bitcoin/difficulty.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
```
### **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 Children Pay for Parent**
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 txid = 'txid';
const feesCPFP = await fees.getCPFP({ txid });
console.log(feesCPFP);
```
### **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} txhex
[ [NodeJS Example](examples/nodejs/bitcoin/transactions.ts) ] [ [HTML Example](examples/html/bitcoin/transactions.html) ] [ [Top](#features) ]
```js
const {
bitcoin: { transactions },
} = mempoolJS();
const txhex = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const postTx = await transactions.postTx({ txhex });
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/websocket.ts) ] [ [HTML Example](examples/html/bitcoin/websocket.html) ] [ [Top](#features) ]
#### **Websocket Server**
Only use on server side apps.
```js
const { bitcoin: { websocket } } = mempoolJS();
const init = async () => {
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.block) {
console.log(res.block);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
}
init();
```
#### **Websocket Client**
Only use on browser apps.
```js
const init = async () => {
const {
bitcoin: { websocket },
} = mempoolJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.block) {
console.log(res.block);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
};
init();
```

765
mempool.js/README-liquid.md Normal file
View File

@ -0,0 +1,765 @@
# mempool**JS** - Liquid API
Interface to access Liquid APIs.
[Back to home](./README.md)
---
## **Features**
- 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 Icon](#get-asset-icon)
- [Get Asset Txs](#get-asset-txs)
- [Get Asset Supply](#get-asset-supply)
- [Get Assets Icons](#get-assets-icons)
- 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 = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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 = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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 = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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 = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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} txhex
[ [NodeJS Example](examples/nodejs/liquid/transactions.ts) ] [ [HTML Example](examples/html/liquid/transactions.html) ] [ [Top](#features) ]
```js
const {
liquid: { transactions },
} = mempoolJS();
const txhex = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const postTx = await transactions.postTx({ txhex });
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/websocket.ts) ] [ [HTML Example](examples/html/liquid/websocket.html) ] [ [Top](#features) ]
#### **Websocket Server**
Only use on server side apps.
```js
const { liquid: { websocket } } = mempoolJS();
const init = async () => {
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();
```
#### **Websocket Client**
Only use on browser apps.
```js
const init = async () => {
const {
liquid: { websocket },
} = mempoolJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('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();
```

102
mempool.js/README.md Normal file
View File

@ -0,0 +1,102 @@
# Mempool JS API
[![npm version](https://img.shields.io/npm/v/@mempool/mempool.js.svg?style=flat-square)](https://www.npmjs.org/package/@mempool/mempool.js)
[![NPM](https://img.shields.io/david/mempool/mempool.js.svg?style=flat-square)](https://david-dm.org/mempool/mempool.js#info=dependencies)
[![Known Vulnerabilities](https://snyk.io/test/github/mempool/mempool.js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/mempool.js)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
NPM package module for Mempool APIs.
Documentation: [https://mempool.space/api](https://mempool.space/api)
---
## **Installation**
### **ES Modules**
Install the npm module.
```bash
# npm
$ npm install @mempool/mempool.js --save
# yarn
$ 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.
Import the module.
```js
import mempoolJS from '@mempool/mempool.js';
// default mempool.space endpoints
const { bitcoin, bisq, liquid } = mempoolJS();
// (optional) your custom endpoints
const { bitcoin, bisq, liquid } = mempoolJS({
hostname: 'mempool.space',
network: 'testnet' // 'signet' | 'testnet' | 'mainnet'
});
```
### **CommonJS**
Include the line below in the `head` tag of your html file.
```html
<script type="text/javascript" src="https://mempool.space/mempool.js"></script>
```
Call `mempoolJS()` function to access the API methods.
```js
// default mempool.space endpoints
const { bitcoin, bisq, liquid } = mempoolJS();
// (optional) your custom endpoints
const { bitcoin, bisq, liquid } = mempoolJS({
hostname: 'mempool.space',
network: 'testnet' // 'signet' | 'testnet' | 'mainnet'
});
```
---
## **Features**
- [Bitcoin](./README-bitcoin.md)
- [Addresses](./README-bitcoin.md#get-address)
- [Blocks](./README-bitcoin.md#get-blocks)
- [Difficulty Adjustment](./README-bitcoin.md#get-difficulty-adjustment)
- [Fees](./README-bitcoin.md#get-fees)
- [Mempool](./README-bitcoin.md#get-mempool)
- [Transactions](./README-bitcoin.md#get-transactions)
- [Websocket Client](./README-bitcoin.md#Websocket-Client)
- [Websocket Server](./README-bitcoin.md#Websocket-Server)
- [Bisq](./README-bisq.md#get-address)
- [Addresses](./README-bisq.md#get-address)
- [Blocks](./README-bisq.md#get-blocks)
- [Statistics](./README-bisq.md#get-statistics)
- [Transactions](./README-bisq.md#get-transactions)
- [Liquid](./README-liquid.md#get-address)
- [Addresses](./README-liquid.md#get-address)
- [Assets](./README-liquid.md#get-address)
- [Blocks](./README-liquid.md#get-address)
- [Fees](./README-liquid.md#get-address)
- [Mempool](./README-liquid.md#get-address)
- [Transactions](./README-liquid.md#get-address)
- [Websocket Client](./README-liquid.md#Websocket-Client)
- [Websocket Server](./README-liquid.md#Websocket-Server)
---
## **Contributing**
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
---
## **License** [MIT](https://choosealicense.com/licenses/mit/)

0
mempool.js/dist/.gitkeep vendored Normal file
View File

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/bisq.js"></script>
<script>
const init = async () => {
try {
const { addresses } = bisqJS();
const address = 'B1DgwRN92rdQ9xpEVCdXRfgeqGw9X4YtrZz';
const myAddress = await addresses.getAddress({ address });
console.log(myAddress);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/bisq.js"></script>
<script>
const init = async () => {
try {
const { blocks } = bisqJS();
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/bisq.js"></script>
<script>
const init = async () => {
try {
const { markets } = bisqJS();
const market = "BTC_USD";
const basecurrency = "BTC";
const allMarkets = await markets.getMarkets();
console.log(allMarkets);
const currencies = await markets.getCurrencies();
console.log(currencies);
const depth = await markets.getDepth({ market });
console.log(depth)
const hloc = await markets.getHloc({ market });
console.log(hloc);
const offers = await markets.getOffers({ market });
console.log(offers);
const ticker = await markets.getTicker({ market });
console.log(ticker);
const trades = await markets.getTrades({ market });
console.log(trades);
const volumes = await markets.getVolumes({ basecurrency, market });
console.log(volumes);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/bisq.js"></script>
<script>
const init = async () => {
try {
const { statistics } = bisqJS();
const stats = await statistics.getStats();
console.log(stats);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/bisq.js"></script>
<script>
const init = async () => {
try {
const { transactions } = bisqJS();
const txid =
'4b5417ec5ab6112bedf539c3b4f5a806ed539542d8b717e1c4470aa3180edce5';
const tx = await transactions.getTx({ txid });
console.log(tx);
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { addresses } = liquidJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { assets } = liquidJS();
const asset_id = 'a0c358a0f6947864af3a06f3f6a2aeb304df7fd95c922f2f22d7412399ce7691';
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { blocks } = liquidJS();
const hash =
'54f02bdec5509ea769c8be82aed51f689969b653d92a2812d5a36266cbfbc55e';
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: 0 });
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { fees } = liquidJS();
const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { mempool } = liquidJS();
const getMempool = await mempool.getMempool();
console.log(getMempool);
const getMempoolRecent = await mempool.getMempoolRecent();
console.log(getMempoolRecent);
const getMempoolTxids = await mempool.getMempoolTxids();
console.log(getMempoolTxids);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { transactions } = liquidJS();
const txid =
'f4e0cae35f8eb239c1eee9177884582aa6e4ce41e919f276617e9c7557168b53';
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 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 txMerkleBlockProof = await transactions.getTxMerkleBlockProof({ txid });
console.log(txMerkleBlockProof);
// const postTx = await transactions.postTx({ txhex });
// console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../dist/liquid.js"></script>
<script>
const init = async () => {
try {
const { websocket } = liquidJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('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);
}
});
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

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

View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

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

View File

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

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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 blockHeader = await blocks.getBlockHeader({ hash });
console.log(blockHeader);
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

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

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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({ txhex });
console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
bitcoin: { websocket },
} = mempoolJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('message', function incoming({data}) {
const res = JSON.parse(data.toString());
if (res.block) {
console.log(res.block);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res.mempoolBlocks) {
console.log(res.mempoolBlocks);
}
});
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
liquid: { assets },
} = mempoolJS();
const asset_id = 'a0c358a0f6947864af3a06f3f6a2aeb304df7fd95c922f2f22d7412399ce7691';
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
liquid: { blocks },
} = mempoolJS();
const hash =
'54f02bdec5509ea769c8be82aed51f689969b653d92a2812d5a36266cbfbc55e';
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: 0 });
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

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

View File

@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
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({ txhex });
// console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="./../../../../dist/mempool.js"></script>
<script>
const init = async () => {
try {
const {
liquid: { websocket },
} = mempoolJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('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);
}
});
} catch (error) {
console.log(error);
}
};
init();
</script>
</head>
<body></body>
</html>

View File

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

View File

@ -0,0 +1,24 @@
import bisqJS from "./../../../src/index-bisq";
const init = async () => {
try {
const { blocks } = bisqJS();
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,38 @@
import bisqJS from "./../../../src/index-bisq";
const init = async () => {
try {
const { markets } = bisqJS();
const market = "BTC_USD";
const basecurrency = "BTC";
const allMarkets = await markets.getMarkets();
console.log(allMarkets);
const currencies = await markets.getCurrencies();
console.log(currencies);
const depth = await markets.getDepth({ market });
console.log(depth)
const hloc = await markets.getHloc({ market });
console.log(hloc);
const offers = await markets.getOffers({ market });
console.log(offers);
const ticker = await markets.getTicker({ market });
console.log(ticker);
const trades = await markets.getTrades({ market });
console.log(trades);
const volumes = await markets.getVolumes({ basecurrency, market });
console.log(volumes);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,13 @@
import bisqJS from "./../../../src/index-bisq";
const init = async () => {
try {
const { statistics } = bisqJS();
const stats = await statistics.getStats();
console.log(stats);
} catch (error) {
console.log(error);
}
};
init();

View File

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

View File

@ -0,0 +1,29 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,24 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,45 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const {
liquid: { 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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,18 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
const {
liquid: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,21 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,45 @@
import mempoolJS from "./../../../src/index";
const init = async () => {
try {
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({ txhex });
// console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,30 @@
import mempoolJS from "./../../../src/index";
const { liquid: { websocket } } = mempoolJS();
const init = async () => {
try {
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);
}
});
} catch (error) {
console.log(error);
}
}
init();

View File

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

View File

@ -0,0 +1,27 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,40 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
const {
bisq: { markets },
} = mempoolJS();
const market = "BTC_USD";
const basecurrency = "BTC";
const allMarkets = await markets.getMarkets();
console.log(allMarkets);
const currencies = await markets.getCurrencies();
console.log(currencies);
const depth = await markets.getDepth({ market });
console.log(depth)
const hloc = await markets.getHloc({ market });
console.log(hloc);
const offers = await markets.getOffers({ market });
console.log(offers);
const ticker = await markets.getTicker({ market });
console.log(ticker);
const trades = await markets.getTrades({ market });
console.log(trades);
const volumes = await markets.getVolumes({ basecurrency, market });
console.log(volumes);
} catch (error) {
console.log(error);
}
};
init();

View File

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

View File

@ -0,0 +1,21 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,27 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,49 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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 blockHeader = await blocks.getBlockHeader({ hash });
console.log(blockHeader);
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,15 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
const {
bitcoin: { difficulty },
} = mempoolJS();
const difficultyAdjustment = await difficulty.getDifficultyAdjustment();
console.log(difficultyAdjustment);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,23 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,21 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,45 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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({ txhex });
// console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,30 @@
import mempoolJS from "./../../../../src/index";
const { bitcoin: { websocket } } = mempoolJS();
const init = async () => {
try {
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);
}
});
} catch (error) {
console.log(error);
}
}
init();

View File

@ -0,0 +1,29 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,24 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,45 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
const {
liquid: { 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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,18 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
const {
liquid: { fees },
} = mempoolJS();
const feesRecommended = await fees.getFeesRecommended();
console.log(feesRecommended);
const feesMempoolBlocks = await fees.getFeesMempoolBlocks();
console.log(feesMempoolBlocks);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,21 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,45 @@
import mempoolJS from "./../../../../src/index";
const init = async () => {
try {
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({ txhex });
// console.log(postTx);
} catch (error) {
console.log(error);
}
};
init();

View File

@ -0,0 +1,30 @@
import mempoolJS from "./../../../../src/index";
const { liquid: { websocket } } = mempoolJS();
const init = async () => {
try {
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);
}
});
} catch (error) {
console.log(error);
}
}
init();

6
mempool.js/nodemon.json Normal file
View File

@ -0,0 +1,6 @@
{
"watch": ["src", "examples"],
"ext": "ts,json",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node ./src/index.ts"
}

6
mempool.js/npm-bisq-js/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/node_modules
/lib
/dist/*
!.gitkeep
yarn-error.log

View File

@ -0,0 +1,265 @@
# Bisq**JS** - Features
Interface to access the Bisq API.
[Back to home](./README.md)
---
## **Features**
- Addresses
- [Get Address](#get-address)
- Blocks
- [Get Block](#get-block)
- [Get Blocks](#get-blocks)
- [Get Block Tip Height](#get-block-tip-height)
- Markets
- [Get Currencies](#get-currencies)
- [Get Depth](#get-depth)
- [Get HLOC](#get-hloc)
- [Get Markets](#get-markets)
- [Get Offers](#get-offers)
- [Get Ticker](#get-ticker)
- [Get Trades](#get-trades)
- [Get Volumes](#get-volumes)
- Statistics
- [Get Statistics](#get-statistics)
- Transactions
- [Get Transaction](#get-transaction)
- [Get Transactions](#get-transactions)
---
### **Get Address**
Returns statistics about all Bisq transactions.
[ [NodeJS Example](../examples/nodejs/bisq-js/addresses.ts) ] [ [HTML Example](../examples/html/bisq-js/addresses.html) ] [ [Top](#features) ]
```js
const { addresses } = bisqJS();
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-js/blocks.ts) ] [ [HTML Example](../examples/html/bisq-js/blocks.html) ] [ [Top](#features) ]
```js
const { blocks } = bisqJS();
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-js/blocks.ts) ] [ [HTML Example](../examples/html/bisq-js/blocks.html) ] [ [Top](#features) ]
```js
const { blocks } = bisqJS();
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-js/blocks.ts) ] [ [HTML Example](../examples/html/bisq-js/blocks.html) ] [ [Top](#features) ]
```js
const { blocks } = bisqJS();
const myBlocksHeight = await blocks.getBlocksTipHeight({
index: 0,
length: 1,
});
console.log(myBlocksHeight);
```
### **Get Market Currencies**
Returns the Bisq market currencies.
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const currencies = await markets.getCurrencies();
console.log(currencies);
```
### **Get Market Depth**
Returns the Bisq market depth.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const depth = await markets.getDepth({ market });
console.log(depth)
```
### **Get Market HLOC**
Returns the Bisq market Hloc.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const hloc = await markets.getHloc({ market });
console.log(hloc);
```
### **Get Market Offers**
Returns the Bisq market Offers.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const offers = await markets.getOffers({ market });
console.log(offers);
```
### **Get Market Ticker**
Returns the Bisq market Ticker.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const ticker = await markets.getTicker({ market });
console.log(ticker);
```
### **Get Market Trades**
Returns the Bisq market Trades.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const trades = await markets.getTrades({ market });
console.log(trades);
```
### **Get Market Volumes**
Returns the Bisq market Volumes.
**Parameters:**
- {string} market
[ [NodeJS Example](../examples/nodejs/bisq-js/markets.ts) ] [ [HTML Example](../examples/html/bisq-js/markets.html) ] [ [Top](#features) ]
```js
const { markets } = bisqJS();
const market = "BTC_USD";
const basecurrency = "BTC";
const volumes = await markets.getVolumes({ basecurrency, market });
console.log(volumes);
```
### **Get Stats**
Returns statistics about all Bisq transactions.
[ [NodeJS Example](../examples/nodejs/bisq-js/statistics.ts) ] [ [HTML Example](../examples/html/bisq-js/statistics.html) ] [ [Top](#features) ]
```js
const { statistics } = bisqJS();
const stats = await statistics.getStats();
console.log(stats);
```
### **Get Transaction**
Returns details about a Bisq transaction.
[ [NodeJS Example](../examples/nodejs/bisq-js/transactions.ts) ] [ [HTML Example](../examples/html/bisq-js/transactions.html) ] [ [Top](#features) ]
```js
const { transactions } = bisqJS();
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-js/transactions.ts) ] [ [HTML Example](../examples/html/bisq-js/transactions.html) ] [ [Top](#features) ]
```js
const { transactions } = bisqJS();
const txs = await transactions.getTxs({ index: 0, length: 1 });
console.log(txs);
```

View File

@ -0,0 +1,67 @@
# Bisq**JS** API
[![npm version](https://img.shields.io/npm/v/@mempool/bisq.js.svg?style=flat-square)](https://www.npmjs.org/package/@mempool/bisq.js)
[![NPM](https://img.shields.io/david/mempool/bisq.js.svg?style=flat-square)](https://david-dm.org/mempool/bisq.js#info=dependencies)
[![Known Vulnerabilities](https://snyk.io/test/github/mempool/bisq.js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/bisq.js)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
NPM package module for Bisq APIs.
Documentation: [https://bisq.markets/api](https://bisq.markets/api)
## **Installation**
### **ES Modules**
Install the npm module.
```bash
# npm
$ npm install @mempool/bisq.js --save
# yarn
$ yarn add @mempool/bisq.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.
Import the module.
```js
import bisqJS from '@mempool/bisq.js';
const bisq = bisqJS();
```
### **CommonJS**
Include the line below in the `head` tag of your html file.
```html
<script type="text/javascript" src="https://bisq.markets/bisq.js"></script>
```
Call `bisqJS()` function to access the API methods.
```js
const bisq = bisqJS();
```
---
## **Features**
- [Addresses](./README-bisq.md#get-address)
- [Blocks](./README-bisq.md#get-blocks)
- [Markets](./README-bisq.md#get-markets)
- [Statistics](./README-bisq.md#get-statistics)
- [Transactions](./README-bisq.md#get-transactions)
---
## **Contributing**
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
---
## **License** [MIT](https://choosealicense.com/licenses/mit/)

View File

@ -0,0 +1,57 @@
{
"name": "@mempool/bisq.js",
"version": "2.2.1",
"description": "NPM package module for Bisq APIs.",
"main": "../lib/index-bisq.js",
"keywords": [
"axios",
"bitcoin",
"bisq",
"blockchain",
"html",
"bisq.js",
"mempool.space",
"mempool.js",
"mempool",
"websocket",
"nodejs",
"typescript"
],
"author": "Miguel Medeiros <contact@miguelmedeiros.com.br> (miguelmedeiros.com.br)",
"url": "https://bisq.markets/",
"private": false,
"repository": {
"type": "git",
"url": "git://github.com/mempool/mempool.js.git"
},
"types": "../lib/index-bisq.d.ts",
"scripts": {
"start": "ts-node ../src/index-bisq.ts",
"dev": "nodemon ../src/index-bisq.ts",
"build": "tsc",
"export-js": "tsc | browserify ../lib/index-bisq.js --standalone bisqJS > ../dist/bisq.js | browserify -p tinyify ../lib/index-bisq.js --standalone bisqJS > ../dist/bisq.min.js",
"prepare": "npm run build",
"postversion": "git push && git push --tags"
},
"files": [
"../lib/**/*"
],
"dependencies": {
"axios": "^0.21.1",
"ws": "^7.4.3"
},
"devDependencies": {
"@types/node": "^14.14.25",
"@types/websocket": "^1.0.2",
"@types/ws": "^7.4.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"browserify": "^17.0.0",
"eslint": "^7.19.0",
"nodemon": "^2.0.7",
"tinyify": "^3.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"license": "MIT"
}

6
mempool.js/npm-liquid-js/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/node_modules
/lib
/dist/*
!.gitkeep
yarn-error.log

View File

@ -0,0 +1,763 @@
# Liquid**JS** - Liquid API
Interface to access Liquid APIs.
[Back to home](./README.md)
---
## **Features**
- 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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/addresses.html) ] [ [Top](#features) ]
```js
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/addresses.html) ] [ [Top](#features) ]
```js
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/addresses.html) ] [ [Top](#features) ]
```js
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/addresses.html) ] [ [Top](#features) ]
```js
const {
liquid: { addresses },
} = mempoolJS();
const address = 'Go65t19hP2FuhBMYtgbdMDgdmEzNwh1i48';
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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/addresses.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/blocks.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/fees.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/fees.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/mempool.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/mempool.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/mempool.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/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} txhex
[ [NodeJS Example](../examples/nodejs/liquid-js/transactions.ts) ] [ [HTML Example](../examples/html/liquid-js/transactions.html) ] [ [Top](#features) ]
```js
const {
liquid: { transactions },
} = mempoolJS();
const txhex = '15e10745f15593a899cef391191bdd3d7c12412cc4696b7bcb669d0feadc8521';
const postTx = await transactions.postTx({ txhex });
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-js/websocket.ts) ] [ [HTML Example](../examples/html/liquid-js/websocket.html) ] [ [Top](#features) ]
#### **Websocket Server**
Only use on server side apps.
```js
const { liquid: { websocket } } = mempoolJS();
const init = async () => {
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();
```
#### **Websocket Client**
Only use on browser apps.
```js
const init = async () => {
const {
liquid: { websocket },
} = mempoolJS();
const ws = websocket.initClient({
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
});
ws.addEventListener('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

@ -0,0 +1,70 @@
# Liquid**JS** API
[![npm version](https://img.shields.io/npm/v/@mempool/liquid.js.svg?style=flat-square)](https://www.npmjs.org/package/@mempool/liquid.js)
[![NPM](https://img.shields.io/david/mempool/liquid.js.svg?style=flat-square)](https://david-dm.org/mempool/liquid.js#info=dependencies)
[![Known Vulnerabilities](https://snyk.io/test/github/mempool/liquid.js/badge.svg?style=flat-square)](https://snyk.io/test/github/mempool/liquid.js)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
NPM package module for Liquid Network APIs.
Documentation: [https://liquid.network/api](https://liquid.network/api)
## **Installation**
### **ES Modules**
Install the npm module.
```bash
# npm
$ npm install @mempool/liquid.js --save
# yarn
$ yarn add @mempool/liquid.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.
Import the module.
```js
import liquidJS from '@mempool/liquid.js';
const liquid = liquidJS();
```
### **CommonJS**
Include the line below in the `head` tag of your html file.
```html
<script type="text/javascript" src="https://liquid.network/liquid.js"></script>
```
Call `liquidJS()` function to access the API methods.
```js
const liquid = liquidJS();
```
---
## **Features**
- [Addresses](./README-liquid.md#get-address)
- [Assets](./README-liquid.md#get-address)
- [Blocks](./README-liquid.md#get-address)
- [Fees](./README-liquid.md#get-address)
- [Mempool](./README-liquid.md#get-address)
- [Transactions](./README-liquid.md#get-address)
- [Websocket Client](./README-liquid.md#Websocket-Client)
- [Websocket Server](./README-liquid.md#Websocket-Server)
---
## **Contributing**
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
---
## **License** [MIT](https://choosealicense.com/licenses/mit/)

View File

@ -0,0 +1,56 @@
{
"name": "@mempool/liquid.js",
"version": "2.2.1",
"description": "NPM package module for Liquid APIs.",
"main": "../lib/index-liquid.js",
"keywords": [
"axios",
"bitcoin",
"liquid",
"blockchain",
"html",
"mempool.space",
"mempool.js",
"mempool",
"websocket",
"nodejs",
"typescript"
],
"author": "Miguel Medeiros <contact@miguelmedeiros.com.br> (miguelmedeiros.com.br)",
"url": "https://liquid.network/",
"private": false,
"repository": {
"type": "git",
"url": "git://github.com/mempool/mempool.js.git"
},
"types": "../lib/index-liquid.d.ts",
"scripts": {
"start": "ts-node ../src/index-liquid.ts",
"dev": "nodemon ../src/index-liquid.ts",
"build": "tsc",
"export-js": "tsc | browserify ../lib/index-liquid.js --standalone liquidJS > ../dist/liquid.js | browserify -p tinyify ../lib/index-liquid.js --standalone liquidJS > ../dist/liquid.min.js",
"prepare": "npm run build",
"postversion": "git push && git push --tags"
},
"files": [
"../lib/**/*"
],
"dependencies": {
"axios": "^0.21.1",
"ws": "^7.4.3"
},
"devDependencies": {
"@types/node": "^14.14.25",
"@types/websocket": "^1.0.2",
"@types/ws": "^7.4.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"browserify": "^17.0.0",
"eslint": "^7.19.0",
"nodemon": "^2.0.7",
"tinyify": "^3.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"license": "MIT"
}

10467
mempool.js/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

62
mempool.js/package.json Normal file
View File

@ -0,0 +1,62 @@
{
"name": "@mempool/mempool.js",
"version": "2.3.0",
"description": "NPM package module for Mempool APIs.",
"main": "lib/index.js",
"keywords": [
"axios",
"bitcoin",
"bisq",
"liquid",
"mainet",
"testnet",
"signet",
"blockchain",
"html",
"mempool.space",
"mempool.js",
"mempool",
"websocket",
"nodejs",
"typescript"
],
"author": "Miguel Medeiros <contact@miguelmedeiros.com.br> (miguelmedeiros.com.br)",
"url": "https://mempool.space/",
"private": false,
"repository": {
"type": "git",
"url": "git://github.com/mempool/mempool.js.git"
},
"types": "lib/index.d.ts",
"scripts": {
"start": "ts-node src/index.ts",
"dev": "nodemon src/index.ts",
"build": "tsc",
"export-mempool-js": "tsc | browserify lib/index.js --standalone mempoolJS > dist/mempool.js | browserify -p tinyify lib/index.js --standalone mempoolJS > dist/mempool.min.js",
"export-bisq-js": "tsc | browserify lib/index-bisq.js --standalone bisqJS > dist/bisq.js | browserify -p tinyify lib/index-bisq.js --standalone bisqJS > dist/bisq.min.js",
"export-liquid-js": "tsc | browserify lib/index-liquid.js --standalone liquidJS > dist/liquid.js | browserify -p tinyify lib/index-liquid.js --standalone liquidJS > dist/liquid.min.js",
"prepare": "npm run build",
"postversion": "git push && git push --tags"
},
"files": [
"lib/**/*"
],
"dependencies": {
"axios": "0.24.0",
"ws": "8.3.0"
},
"devDependencies": {
"@types/node": "^14.14.25",
"@types/websocket": "^1.0.2",
"@types/ws": "^7.4.1",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"browserify": "^17.0.0",
"eslint": "^7.19.0",
"nodemon": "^2.0.7",
"tinyify": "^3.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"license": "MIT"
}

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>(`/address/${params.address}`);
return data;
};
return {
getAddress,
};
};

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,137 @@
import { AxiosInstance } from 'axios';
import { Currencies, Depth, Markets, Hloc, MarketsInstance, Offers, Trades, Volumes } from '../../interfaces/bisq/markets';
export const useMarkets = (api: AxiosInstance): MarketsInstance => {
const getCurrencies = async (
params: {
basecurrency?: string;
type?: string;
format?: string;
} = {
basecurrency: 'BTC',
type: 'all',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Currencies>('/currencies', { params });
return data;
};
const getDepth = async (
params: {
market: string;
format?: string;
} = {
market: 'xmr_btc',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Depth>('/depth', { params });
return data;
};
const getHloc = async (params: {
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
}) => {
const { data } = await api.get<Hloc[]>('/hloc', { params });
return data;
};
const getMarkets = async (
params: {
format?: string;
} = {
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Markets>('/markets', { params });
return data;
};
const getOffers = async (
params: {
market: string;
direction?: string;
format?: string;
} = {
market: 'xmr_btc',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Offers>('/offers', { params });
return data;
};
const getTicker = async (
params: {
market?: string;
format?: string;
} = {
format: 'jsonpretty',
}
) => {
const { data } = await api.get('/ticker', { params });
return data;
};
const getTrades = async (
params: {
market: string;
format?: string;
timestamp_from?: string;
timestamp_to?: string;
trade_id_from?: string;
trade_id_to?: string;
limit?: number;
sort?: string;
} = {
market: 'all',
format: 'jsonpretty',
timestamp_from: '2016-01-01',
timestamp_to: 'now',
limit: 100,
sort: 'desc',
}
) => {
const { data } = await api.get<Trades[]>('/trades', { params });
return data;
};
const getVolumes = async (
params: {
basecurrency: string;
market: string;
interval?: string;
timestamp_from?: string;
timestamp_to?: string;
format?: string;
} = {
basecurrency: '',
market: '',
interval: 'auto',
timestamp_from: '2016-01-01',
timestamp_to: 'now',
format: 'jsonpretty',
}
) => {
const { data } = await api.get<Volumes[]>('/trades', { params });
return data;
};
return {
getCurrencies,
getDepth,
getHloc,
getMarkets,
getOffers,
getTicker,
getTrades,
getVolumes,
};
};

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

@ -0,0 +1,85 @@
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 getBlockHeader = async (params: { hash: string }) => {
const { data } = await api.get<string>(`/block/${params.hash}/header`);
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,
getBlockHeader,
getBlockHeight,
getBlocksTipHash,
getBlocksTipHeight,
};
};

View File

@ -0,0 +1,16 @@
import { AxiosInstance } from 'axios';
import {
Adjustment,
DifficultyInstance,
} from '../../interfaces/bitcoin/difficulty';
export const useDifficulty = (api: AxiosInstance): DifficultyInstance => {
const getDifficultyAdjustment = async () => {
const { data } = await api.get<Adjustment>(`/v1/difficulty-adjustment`);
return data;
};
return {
getDifficultyAdjustment,
};
};

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,
};
};

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: { txhex: string }) => {
const { data } = await api.post<string>(`/tx`, { txhex: params.txhex });
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';
export const useWebsocket = (hostname: string, network: string): WsInstance => {
const wsEndpoint = `wss://${hostname}${network === 'main' ? '' : `/${network}`}/api/v1/ws`;
return {
initClient: ({ options }: WsInterface) =>
wsClient(options, wsEndpoint),
initServer: ({ options }: WsInterface) =>
wsServer(options, wsEndpoint),
};
};

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

@ -0,0 +1,49 @@
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 getAssetIcon = async (params: { asset_id: string }) => {
const { data } = await api.get(`/v1/asset/${params.asset_id}/icon`);
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;
};
const getAssetsIcons = async () => {
const { data } = await api.get<string[]>(`/v1/assets/icons`);
return data;
};
return {
getAsset,
getAssetIcon,
getAssetTxs,
getAssetSupply,
getAssetsIcons,
};
};

View File

@ -0,0 +1,79 @@
import { AxiosInstance } from 'axios';
import {
Block,
BlockStatus,
BlockLiquidInstance,
} from '../../interfaces/liquid/block';
import { Tx } from '../../interfaces/bitcoin/transactions';
export const useBlocks = (api: AxiosInstance): BlockLiquidInstance => {
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,
};
};

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,
};
};

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: { txhex: string }) => {
const { data } = await api.post<string>(`/tx`, { txid: params.txhex });
return data;
};
return {
getTx,
getTxStatus,
getTxHex,
getTxRaw,
getTxMerkleBlockProof,
getTxMerkleProof,
getTxOutspend,
getTxOutspends,
postTx,
};
};

Some files were not shown because too many files have changed in this diff Show More