npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@oipwg/insight-explorer

v2.0.1

Published

Easily retrieve information about transactions and addresses from any insight api explorer

Downloads

115

Readme

Insight Explorer

A simple NPM Module to get data back easily from any coins Insight API server. Created as a more compatable "open" version, vs being locked to a specific coin.

This module connects to a running Insight API service. If you're looking for information on how to run your own node, take a look at https://github.com/bitpay/insight-api.

Installation

To add the Insight Explorer to your project, just install it with your favorite package manager. For example, using the default NPM you can install it like this.

npm install --save insight-explorer

Usage Instructions

To use the Insight explorer, first import the package into your node application.

import { Insight } from 'insight-explorer'

After you have imported the package, you will then need to create a new Insight object and give it your Insight API URL.

let explorer = new Insight("https://livenet.flocha.in/api")

Now that we have created our Insight Explorer with the Insight API URL, we can query data from the blockchain.

Block

You can get a block back by querying based on its hash.

explorer.getBlock("block_hash").then(function(block){
    console.log(block);
})

Block Index

Get block hash by height

explorer.getBlockIndex("block_height").then(function(block){
    console.log(block);
})

This would return:

{
  "blockHash":"block_hash"
}

Raw Block

explorer.getRawBlock("block_hash").then(function(block){
    console.log(block);
})

This would return:

{
  "rawblock":"blockhexstring..."
}

Block Summaries

Get block summaries by date:

explorer.getBlockSummary(3, "2016-04-21").then(function(blocks){
    console.log(blocks);
})

Example response:

{
  "blocks": [
    {
      "height": 408495,
      "size": 989237,
      "hash": "00000000000000000108a1f4d4db839702d72f16561b1154600a26c453ecb378",
      "time": 1461360083,
      "txlength": 1695,
      "poolInfo": {
        "poolName": "BTCC Pool",
        "url": "https://pool.btcc.com/"
      }
    }
  ],
  "length": 1,
  "pagination": {
    "next": "2016-04-23",
    "prev": "2016-04-21",
    "currentTs": 1461369599,
    "current": "2016-04-22",
    "isToday": true,
    "more": true,
    "moreTs": 1461369600
  }
}

Transaction

explorer.getTransaction("txid").then(function(tx){
    console.log(tx);
})

Address

explorer.getAddress("address").then(function(addr){
    console.log(addr);
})

Address Properties

The four supported Properties that you can use are balance, totalReceived, totalSent, and unconfirmedBalance.

explorer.getAddressProperties("address", "balance").then(function(prop){
    console.log(prop);
})

The response contains the value in Satoshis.

Unspent Outputs

explorer.getAddressUtxo("address").then(function(utxos){
    console.log(utxos);
})

Sample return:

[
  {
    "address":"mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs",
    "txid":"d5f8a96faccf79d4c087fa217627bb1120e83f8ea1a7d84b1de4277ead9bbac1",
    "vout":0,
    "scriptPubKey":"76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac",
    "amount":0.000006,
    "satoshis":600,
    "confirmations":0,
    "ts":1461349425
  },
  {
    "address": "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs",
    "txid": "bc9df3b92120feaee4edc80963d8ed59d6a78ea0defef3ec3cb374f2015bfc6e",
    "vout": 1,
    "scriptPubKey": "76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac",
    "amount": 0.12345678,
    "satoshis": 12345678,
    "confirmations": 1,
    "height": 300001
  }
]

Unspent Outputs for Multiple Addresses

explorer.getAddressesUtxo(["address1", "address2"]).then(function(utxos){
    console.log(utxos);
})

Transactions by Block

explorer.getTransactionsForBlock("block_hash").then(function(txs){
    console.log(txs);
})

Transactions by Address

explorer.getTransactionsForAddress("address").then(function(txs){
    console.log(txs);
})

Transactions for Multiple Addresses

explorer.getTransactionsForAddresses(["address1", "address2"], options).then(function(txs){
    console.log(txs);
})
Options
from (optional): 0
to (optional): 20
noAsm (optional): 1 (will omit script asm from results)
noScriptSig (optional): 1 (will omit the scriptSig from all inputs)
noSpent (option): 1 (will omit spent information per output)
Sample output
{ totalItems: 100,
  from: 0,
  to: 20,
  items:
    [ { txid: '3e81723d069b12983b2ef694c9782d32fca26cc978de744acbc32c3d3496e915',
       version: 1,
       locktime: 0,
       vin: [Object],
       vout: [Object],
       blockhash: '00000000011a135e5277f5493c52c66829792392632b8b65429cf07ad3c47a6c',
       confirmations: 109367,
       time: 1393659685,
       blocktime: 1393659685,
       valueOut: 0.3453,
       size: 225,
       firstSeenTs: undefined,
       valueIn: 0.3454,
       fees: 0.0001 },
      { ... },
      { ... },
      ...
      { ... }
    ]
 }

Note: if pagination params are not specified, the result is an array of transactions.

Transaction Broadcasting

explorer.broadcastRawTransaction("raw_tx_hex").then(function(res){
    console.log(res);
})
Sample response
  {
      txid: [:txid]
  }

  eg

  {
      txid: "c7736a0a0046d5a8cc61c8c3c2821d4d7517f5de2bc66a966011aaa79965ffba"
  }

Historic Blockchain Data Sync Status

explorer.getSync().then(function(info){
    console.log(info);
})

Live Network P2P Data Sync Status

explorer.getPeer().then(function(info){
    console.log(info);
})

Status of the Bitcoin Network

explorer.getStatus("option").then(function(info){
    console.log(info);
})

Get Exchange Rate

explorer.getExchangeRate().then(function(info){
    console.log(info);
})

Where option can be:

  • getInfo
  • getDifficulty
  • getBestBlockHash
  • getLastBlockHash

Utility Methods

explorer.estimateFee(nbBlocks).then(function(fee){
    console.log(fee);
})

Listen for new Transactions

This is sent anytime a transaction gets added to the mempool

explorer.onTX(function(tx){
    console.log("Transaction Recieved! ", tx);
})

Listen for new Blocks

This is sent anytime a block gets added to the chain

explorer.onBlock(function(block){
    console.log("Block Recieved! ", block);
})

Listen for Address updates

This is sent anytime an address recieves or spends a transaction. If the address was used in a spend, the type will be seen_in_tx_input, if the address recieved funds, the type will be seen_in_tx_output.

explorer.onAddressUpdate("odqpABssS7twQfwqNhQdb58c8RiG6awnCh", function(tx){
    console.log("Address Update for odqpABssS7twQfwqNhQdb58c8RiG6awnCh Recieved! ", tx);
})

Example Output

{ 
    type: 'seen_in_tx_output',
    txid: '2ffaefefe962698653160d135ee43c34d22487c47949cc944cf6f05436ee2b93',
    updated_data: { 
        addrStr: 'odqpABssS7twQfwqNhQdb58c8RiG6awnCh',
        balance: 4.84555612,
        balanceSat: 484555612,
        totalReceived: 8.84422124,
        totalReceivedSat: 884422124,
        totalSent: 3.99866512,
        totalSentSat: 399866512,
        unconfirmedBalance: 0.132,
        unconfirmedBalanceSat: 13200000,
        unconfirmedTxApperances: 1,
        txApperances: 57 
    } 
}

License

(The MIT License)

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.