blockpulsar-client-ts v1.0.0
Blockpulsar TypeScript Client
Official TypeScript client for Blockpulsar API
- Website: https://blockpulsar.com
- API documentation: https://blockpulsar-docs.web.app/
- API version: 1.0.0
- Package version: 1.0.0
Install
npm install --save blockpulsar-client-ts
Usage
Import the module first and instantiate a BlockpulsarClient
object.
import { BlockpulsarClient } from 'blockpulsar-client-ts';
const bp_client = new BlockpulsarClient({api_key: 'bpapikey', secret_key: 'bpsecretkey'});
Note: It is recommended api_key
and secret_key
to be specified by setting the BLOCKPULSAR_API_KEY
and BLOCKPULSAR_SECRET_KEY
environment
variables in .env
file, respectively. See an example below.
Example
Create a .env
file and provide the BLOCKPULSAR_API_KEY
and BLOCKPULSAR_SECRET_KEY
environment variables.
Install dotenv
module (npm install dotenv
) to load the environment variables from the .env
file.
import { BlockpulsarClient } from 'blockpulsar-client-ts';
import 'dotenv/config';
(async () => {
try {
const bp_client = new BlockpulsarClient({
api_key: String(process.env.BLOCKPULSAR_API_KEY),
secret_key: String(process.env.BLOCKPULSAR_SECRET_KEY)
});
const block_hash: string = await bp_client.btc.getBestBlockHash();
const block = await bp_client.btc.getBlock(block_hash);
console.log(block);
} catch (e) {
console.error(e);
}
})();
Methods
All the BlockpulsarClient
methods are async
and return promise.
// Returns the hash of the best (tip) block in the most-work fully-validated chain.
getBestBlockHash()
// Get block.
//
// Args:
// -blockhash: The block hash
getBlock(blockhash: string)
// Returns an object containing various state info regarding blockchain processing.
getBlockchainInfo()
// Returns the height of the most-work fully-validated chain. The genesis block has height 0.
getBlockCount()
// Returns hash of block in best-block-chain at height provided.
//
// Args:
// -height: The height index. The genesis block has height 0
getBlockHash(height: number)
// Get block header
//
// Args:
// -blockhash: The block hash
getBlockHeader(blockhash: string)
// Compute per block statistics for a given window. All amounts are in satoshis.
// It won’t work for some heights with pruning.
//
// Args:
// -hash_or_height: The block hash or height of the target block
getBlockStats(hash_or_height: string | number)
// Return information about all known tips in the block tree, including the main chain
// as well as orphaned branches.
getChainTips()
// Compute statistics about the total number and rate of transactions in the chain.
//
// Args:
// -blockhash: (optional) The hash of the block that ends the window. Default is chain tip
// -nblocks: (optional) Size of the window in number of blocks. Default is one month (30)
getChainTxStats(blockhash: string, nblocks: number = 30)
// Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
getDifficulty()
// Get memory pool ancestors.
//
// Args:
// -txid: The transaction id (must be in mempool)
getMemPoolAncestors(txid: string)
// Get memory pool descendants.
//
// Args:
// -txid: The transaction id (must be in mempool)
getMemPoolDescendants(txid: string)
// Returns mempool data for given transaction.
//
// Args:
// -txid: The transaction id (must be in mempool)
getMemPoolEntry(txid: string)
// Returns details on the active state of the transaction memory pool.
getMemPoolInfo()
// Get raw memory pool data. An array of TX IDs.
getRawMemPool()
// Returns details about an unspent transaction output.
//
// Args:
// -txid: The transaction ID
// -n: vout number
// -include_mempool: (optional) Whether to include the mempool
// Note that an unspent output that is spent in the mempool won’t appear. Default is true
getTxOut(txid: string, n: number, include_mempool: boolean = true)
// Returns a hex-encoded proof that “txid” was included in a block.
//
// Args:
// -txids: The transaction IDs to filter
// -blockhash: The hash of the block. Looks for txid in the block with this hash if it is provided
getTxOutProof(txids: Array<string>, blockhash: string = '')
// Returns a json object containing mining-related information.
getMiningInfo()
// Returns the estimated network hashes per second based on the last n blocks.
//
// Args:
// -nblocks: (optional) The number of blocks, or -1 for blocks since last difficulty change.
// Default is 120
// -height: (optional) To estimate at the time of the given height. Default is -1
getNetworkHashps(nblocks: number = 120, height: number = -1)
// Get raw transaction. When called with a blockhash argument, getrawtransaction will
// return the transaction if the specified block is available and the transaction is found
// in that block.
//
// Args:
// -txid: The transaction ID
// -blockhash: The block in which to look for the transaction. Default is empty string.
getRawTransaction(txid: string, blockhash: string = '')
// Return information about the given bitcoin address.
//
// Args:
// -address: BTC address to be checked
validateAddress(address: string)
Contributions
Contributions are welcome and can be made by submitting GitHub pull requests to this repository. In general, the
blockpulsar-client-ts
source code follows Airbnb JavaScript Style Guide
and rules specified in .eslintrc.json
file.
License
This source code is available to everyone under the standard Apache-2.0 License.
3 years ago