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.
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 = "https://livenet.flocha.in/api"
If you would like to disable websockets, then you can pass false
as the second paramater to creating a new Insight
object. This will turn off Websocket updates. Websockets are default on.
let explorer = "https://livenet.flocha.in/api" false
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
Block Index
Get block hash by height
explorer
This would return:
"blockHash":"block_hash"
Raw Block
explorer
This would return:
"rawblock":"blockhexstring..."
Block Summaries
Get block summaries by date:
explorer
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
Address
explorer
Address Properties
The four supported Properties that you can use are balance
, totalReceived
, totalSent
, and unconfirmedBalance
.
explorer
The response contains the value in Satoshis.
Unspent Outputs
explorer
Sample return:
"address":"mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs" "txid":"d5f8a96faccf79d4c087fa217627bb1120e83f8ea1a7d84b1de4277ead9bbac1" "vout":0 "scriptPubKey":"76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac" "amount":0000006 "satoshis":600 "confirmations":0 "ts":1461349425 "address": "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs" "txid": "bc9df3b92120feaee4edc80963d8ed59d6a78ea0defef3ec3cb374f2015bfc6e" "vout": 1 "scriptPubKey": "76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac" "amount": 012345678 "satoshis": 12345678 "confirmations": 1 "height": 300001
Unspent Outputs for Multiple Addresses
explorer
Transactions by Block
explorer
Transactions by Address
explorer
Transactions for Multiple Addresses
explorer
Options
: 0: 20: : :
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: 03453 size: 225 firstSeenTs: undefined valueIn: 03454 fees: 00001 ... ... ... ...
Note: if pagination params are not specified, the result is an array of transactions.
Transaction Broadcasting
explorer
Sample response
txid: :txid eg txid: "c7736a0a0046d5a8cc61c8c3c2821d4d7517f5de2bc66a966011aaa79965ffba"
Historic Blockchain Data Sync Status
explorer
Live Network P2P Data Sync Status
explorer
Status of the Bitcoin Network
explorer
Get Exchange Rate
explorer
Where option
can be:
- getInfo
- getDifficulty
- getBestBlockHash
- getLastBlockHash
Utility Methods
explorer
Web Socket API
Listen for new Transactions
This is sent anytime a transaction gets added to the mempool
explorer
Listen for new Blocks
This is sent anytime a block gets added to the chain
explorer
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
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.