You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Bitcoin blockchain REST and web socket API service for [Bitcore Node](https://github.com/bitpay/bitcore-node).
3
4
4
-
*insight API* is an open-source bitcoin blockchain REST
5
-
and websocket API. Insight API runs in NodeJS and uses LevelDB for storage.
6
-
7
-
This is a backend-only service. If you're looking for the web frontend application,
8
-
take a look at https://github.com/bitpay/insight.
9
-
10
-
*Insight API* allows to develop bitcoin-related applications (such as wallets) that
11
-
require certain information from the blockchain that bitcoind does not provide.
12
-
13
-
A blockchain explorer front-end has been developed on top of *Insight API*. It can
14
-
be downloaded at [Github Insight Repository](https://github.com/bitpay/insight).
15
-
16
-
## Warning
17
-
Insight file sync does not work with **bitcoind** v0.10
18
-
In order to use Insigtht you must set the environment variable INSIGHT_FORCE_RPC_SYNC = 1
19
-
We are working on `bitcore-node` to replace Insight-api. Check `bitcore-node` on [github](https://github.com/bitpay/bitcore-node).
5
+
This is a backend-only service. If you're looking for the web frontend application, take a look at https://github.com/bitpay/insight.
20
6
21
7
## Prerequisites
22
8
23
-
***bitcoind** - Download and Install [Bitcoin](http://bitcoin.org/en/download)
24
-
25
-
*insight API* needs a *trusted* bitcoind node to run. *insight API* will connect to the node
26
-
through the RPC API, bitcoin peer-to-peer protocol, and will even read its raw block .dat files for syncing.
27
-
28
-
Configure bitcoind to listen to RPC calls and set `txindex` to true.
29
-
The easiest way to do this is by copying `./etc/bitcoind/bitcoin.conf` to your
30
-
bitcoin data directory (usually `~/.bitcoin` on Linux, `%appdata%\Bitcoin\` on Windows,
31
-
or `~/Library/Application Support/Bitcoin` on Mac OS X).
32
-
33
-
bitcoind must be running and must have finished downloading the blockchain **before** running *insight API*.
34
-
35
-
36
-
***Node.js v0.10.x** - Download and Install [Node.js](http://www.nodejs.org/download/).
37
-
38
-
***NPM** - Node.js package manager, should be automatically installed when you get node.js.
39
-
40
-
41
-
## Quick Install
42
-
Check the Prerequisites section above before installing.
43
-
44
-
To install Insight API, clone the main repository:
45
-
46
-
$ git clone https://github.com/bitpay/insight-api && cd insight-api
47
-
48
-
Install dependencies:
49
-
50
-
$ npm install
51
-
52
-
Run the main application:
53
-
54
-
$ node insight.js
55
-
56
-
Then open a browser and go to:
57
-
58
-
http://localhost:3001
59
-
60
-
Please note that the app will need to sync its internal database
61
-
with the blockchain state, which may take some time. You can check
62
-
sync progress at http://localhost:3001/api/sync.
63
-
64
-
65
-
## Configuration
66
-
67
-
All configuration is specified in the [config](config/) folder, particularly the [config.js](config/config.js) file. There you can specify your application name and database name. Certain configuration values are pulled from environment variables if they are defined:
68
-
69
-
```
70
-
BITCOIND_HOST # RPC bitcoind host
71
-
BITCOIND_PORT # RPC bitcoind Port
72
-
BITCOIND_P2P_HOST # P2P bitcoind Host (will default to BITCOIND_HOST, if specified)
73
-
BITCOIND_P2P_PORT # P2P bitcoind Port
74
-
BITCOIND_USER # RPC username
75
-
BITCOIND_PASS # RPC password
76
-
BITCOIND_DATADIR # bitcoind datadir. 'testnet3' will be appended automatically if testnet is used. NEED to finish with '/'. e.g: `/vol/data/`
77
-
INSIGHT_NETWORK [= 'livenet' | 'testnet']
78
-
INSIGHT_PORT # insight api port
79
-
INSIGHT_DB # Path where to store insight's internal DB. (defaults to $HOME/.insight)
80
-
INSIGHT_SAFE_CONFIRMATIONS=6 # Nr. of confirmation needed to start caching transaction information
81
-
INSIGHT_IGNORE_CACHE # True to ignore cache of spents in transaction, with more than INSIGHT_SAFE_CONFIRMATIONS confirmations. This is useful for tracking double spents for old transactions.
82
-
ENABLE_CURRENCYRATES # if "true" will enable a plugin to obtain historic conversion rates for various currencies
83
-
ENABLE_RATELIMITER # if "true" will enable the ratelimiter plugin
84
-
LOGGER_LEVEL # defaults to 'info', can be 'debug','verbose','error', etc.
85
-
ENABLE_HTTPS # if "true" it will server using SSL/HTTPS
86
-
ENABLE_EMAILSTORE # if "true" will enable a plugin to store data with a validated email address
87
-
INSIGHT_EMAIL_CONFIRM_HOST # Only meanfull if ENABLE_EMAILSTORE is enable. Hostname for the confirm URLs. E.g: 'https://insight.bitpay.com'
88
-
89
-
```
90
-
91
-
Make sure that bitcoind is configured to [accept incoming connections using 'rpcallowip'](https://en.bitcoin.it/wiki/Running_Bitcoin).
92
-
93
-
In case the network is changed (testnet to livenet or vice versa) levelDB database needs to be deleted. This can be performed running:
94
-
```util/sync.js -D``` and waiting for *insight* to synchronize again. Once the database is deleted, the sync.js process can be safely interrupted (CTRL+C) and continued from the synchronization process embedded in main app.
95
-
96
-
## Synchronization
97
-
98
-
The initial synchronization process scans the blockchain from the paired bitcoind server to update addresses and balances. *insight-api* needs exactly one trusted bitcoind node to run. This node must have finished downloading the blockchain before running *insight-api*.
While *insight* is synchronizing the website can be accessed (the sync process is embedded in the webserver), but there may be missing data or incorrect balances foraddresses. The'sync' status is shown at the `/api/sync` endpoint.
101
-
102
-
The blockchain can be read from bitcoind's raw `.dat` files or RPC interface.
103
-
Reading the information from the `.dat` files is much faster so it's the
104
-
recommended (and default) alternative. `.dat` files are scanned in the default
105
-
location for each platform (for example, `~/.bitcoin` on Linux). In case a
106
-
non-standard location is used, it needs to be defined (see the Configuration section).
107
-
As of June 2014, using `.dat` files the sync process takes 9 hrs.
108
-
for livenet and 30mins. for testnet.
109
-
110
-
While synchronizing the blockchain, *insight-api* listens fornewblocks and
111
-
transactions relayed by the bitcoind node. Those are also stored on *insight-api*'s database.
112
-
In case *insight-api* is shutdown for a period of time, restarting it will trigger
113
-
a partial (historic) synchronization of the blockchain. Depending on the size of
114
-
that synchronization task, a reverse RPC or forward `.dat` syncing strategy will be used.
115
-
116
-
If bitcoind is shutdown, *insight-api* needs to be stopped and restarted
117
-
once bitcoind is restarted.
118
-
119
-
### Syncing old blockchain data manually
120
-
121
-
Old blockchain data can be manually synced issuing:
122
-
123
-
$ util/sync.js
124
-
125
-
Check util/sync.js --help for options, particulary -D to erase the current DB.
126
-
127
-
*NOTE*: there is no need to run this manually since the historic synchronization
128
-
is built in into the web application. Running *insight-api* normally will trigger
129
-
the historic sync automatically.
130
-
131
-
132
-
### DB storage requirement
133
-
134
-
To store the blockchain and address related information, *insight-api* uses LevelDB.
135
-
Two DBs are created: txs and blocks. By default these are stored on
136
-
137
-
``~/.insight/``
138
-
139
-
Please note that some older versions of Insight-API store that on `<insight's root>/db`.
140
-
141
-
This can be changed at config/config.js. As of June 2014, storing the livenet blockchain takes ~35GB of disk space (2GB for the testnet).
142
-
143
-
## Development
144
-
145
-
To run insight locally for development with grunt:
146
-
147
-
```$ NODE_ENV=development grunt```
148
-
149
-
To run the tests
150
-
151
-
```$ grunt test```
152
-
153
-
154
-
Contributions and suggestions are welcome at [insight-api github repository](https://github.com/bitpay/insight-api).
155
-
156
-
## Caching schema
157
-
158
-
Since v0.2 a new cache schema has been introduced. Only information from transactions with
159
-
INSIGHT_SAFE_CONFIRMATIONS settings will be cached (by default SAFE_CONFIRMATIONS=6). There
160
-
are 3 different caches:
161
-
* Number of confirmations
162
-
* Transaction output spent/unspent status
163
-
* scriptPubKey for unspent transactions
164
-
165
-
Cache data is only populated on request, i.e., only after accessing the required data for
166
-
the first time, the information is cached, there is not pre-caching procedure. To ignore
167
-
cache by default, use INSIGHT_IGNORE_CACHE. Also, address related calls support `?noCache=1`
168
-
to ignore the cache in a particular API request.
169
-
170
-
## API
171
-
172
-
By default, insight provides a REST API at `/api`, but this prefix is configurable from the var `apiPrefix` in the `config.js` file.
173
-
174
-
The end-points are:
11
+
**Note:** You can use an existing Bitcoin data directory, however `txindex` needs to be set to true in `bitcoin.conf`.
0 commit comments