<p>Bitpay's <a href="https://github.com/bitpay/bitcore-node" rel="nofollow noreferrer">bitcore-node</a> project uses the same datadirectory as Bitcoin Core. You can see this in their sample configuration in their README:</p>

<pre><code>var configuration = {
    datadir: '~/.bitcoin',
    network: 'testnet'
};
</code></pre>

<p>As such, the you can see: <a href="https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair">What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?</a> for information on what is in this database. However, bitcore-node does provide another interface for storing extra data about addresses and their balances. This is defined in <a href="https://github.com/bitpay/bitcore-node/blob/v0.2.0/lib/modules/address.js" rel="nofollow noreferrer">this file</a>. You have to enable this in your configuration and re-index the blockchain to enable this module, as their README details.</p>

<p><a href="https://github.com/bitpay/bitcore-node/blob/v0.2.0/lib/modules/address.js#L103-L110" rel="nofollow noreferrer">As these lines show</a>, for each output, key-value pairs are added to the leveldb database in this format:</p>

<pre><code>key:   [AddressModule.PREFIXES.OUTPUTS, address, timestamp, txid, outputIndex].join('-'),
value: [output.satoshis, script, height].join(':')
</code></pre>

<p>And, similarly for inputs, this is the format of the key-value pairs:</p>

<pre><code>key: [AddressModule.PREFIXES.SPENTS, input.prevTxId, input.outputIndex].join('-'),
value: [txid, j].join(':')
</code></pre>

CC BY-SA 3.0
2015-08-06T14:53:21.893Z
2015-08-06T14:53:21.893Z
2017-04-13T12:47:32.940Z
morsecoder
<p>I'm looking into the data and source of bitcore-node ( <a href="http://bitcore.io/" rel="nofollow">http://bitcore.io/</a> ), I'm a bit confused how all the information is stored in the database, probably it's in a similar way to others block explorers, so maybe someone could help me.</p>

<p>In this case for example <a href="https://blockchain.info/tx/acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42" rel="nofollow">https://blockchain.info/tx/acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42</a></p>

<p>In the database I found two txo- txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-0</p>

<pre><code>{"prevTxId":"8697331c3124c8a4cf2f43afb5732374ea13769e42f10aa3a98148a08989af5e","outputIndex":1,"sequenceNumber":4294967295,"script":"4730440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","scriptString":"71 0x30440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","heightConfirmed":37514}
</code></pre>

<p>txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-1</p>

<pre><code>{"satoshis":10100000000,"script":"76a91427d25a1ff9a6da31eeb991c48bb6cd95191a6b2c88ac"}
</code></pre>

<p>Clearly different data, not sure why in one case we store the previous txid and in the other just the satoshis sent. It has to be obvious, but not sure what I'm missing here.</p>

<p>Another example <a href="https://blockchain.info/tx/00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b" rel="nofollow">https://blockchain.info/tx/00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b</a></p>

<p>txo-00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b-0 (from 0 to 5 all have similar data)</p>

<pre><code>{"prevTxId":"6aebb4a764a027436f703ca9d42d0735423798f56973f9f236832a91fc2e9026","outputIndex":0,"sequenceNumber":4294967295,"script":"473044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","scriptString":"71 0x3044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","heightConfirmed":10712}
</code></pre>

<p>Also,... they are inputs, not outputs of the transaction.</p>

<p>I'm trying to read the code, but I can't get to understand all the pieces.</p>

<p>As someone points me in reddit, it looks like it's using txo-- to store both, outputs and inputs. So I'm not sure how bitcore manages to get the inputs/outputs separately later (the API allows you to request only the inputs for example).</p>

CC BY-SA 3.0
2015-08-04T15:25:36.683Z
Are you using one of the bitcore sub-projects? I don't see any references to a database in bitcore, or in any of the sub-projects that I looked in, actually.
morsecoder
CC BY-SA 3.0
2015-08-06T05:55:17.510Z
No, I was using the bitcore-node only, but because there were no subproject/module at the moment. They changed quite a bit the code since them, I need to review it again. I'm a bit confused by bitcore (only the library?) and bitcore-node (a full node with DB?), as you have a module for block explorer for bitcore (not bitcore-node) https://github.com/bitpay/bitcore-explorers . The node use a database : https://github.com/bitpay/bitcore-node/blob/master/lib/db.js

Anyway, what I want is the DB key structure, to replicate it on my own
CONEJO
<database><bitcore><leveldb><blockchain-explorer>
Trying to understand how bitcore-node stores the data in the DB
CONEJO
# Trying to understand how bitcore-node stores the data in the DB

(Asked by: username_0 on 2015-07-16)

I'm looking into the data and source of bitcore-node ( <http://bitcore.io/> ), I'm a bit confused how all the information is stored in the database, probably it's in a similar way to others block explorers, so maybe someone could help me.

In this case for example <https://blockchain.info/tx/acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42>

In the database I found two txo- txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-0

```
{"prevTxId":"8697331c3124c8a4cf2f43afb5732374ea13769e42f10aa3a98148a08989af5e","outputIndex":1,"sequenceNumber":4294967295,"script":"4730440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","scriptString":"71 0x30440220106c316c22d4bf8c970f8e4b1af1edd95121397cfe29ab987cb000b478ec8e4302202b77986b89d77ab716da3cf53424efacf35e9097b1c89194df220e99503b8cae01","heightConfirmed":37514}

```

txo-acb2e895a9b3664cfcfb13dd0321ef0c1205cf2aa082681dc6ba424af6456a42-1

```
{"satoshis":10100000000,"script":"76a91427d25a1ff9a6da31eeb991c48bb6cd95191a6b2c88ac"}

```

Clearly different data, not sure why in one case we store the previous txid and in the other just the satoshis sent. It has to be obvious, but not sure what I'm missing here.

Another example <https://blockchain.info/tx/00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b>

txo-00eff263871e6d44abed66d90abb10d5a211441668511dba3146e380360efe4b-0 (from 0 to 5 all have similar data)

```
{"prevTxId":"6aebb4a764a027436f703ca9d42d0735423798f56973f9f236832a91fc2e9026","outputIndex":0,"sequenceNumber":4294967295,"script":"473044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","scriptString":"71 0x3044022057801e812f964bcb9e8ff17b37acef55afbb7119a66f24a148ba65e86a7aa1e3022064af657d280068b979ea17a29969976aedee8a664b3f1b575ebb88ef9275302601","heightConfirmed":10712}

```

Also,... they are inputs, not outputs of the transaction.

I'm trying to read the code, but I can't get to understand all the pieces.

As someone points me in reddit, it looks like it's using txo-- to store both, outputs and inputs. So I'm not sure how bitcore manages to get the inputs/outputs separately later (the API allows you to request only the inputs for example).

**Tags:** database, bitcore, leveldb, blockchain-explorer

> **Comments:**
> **username_1**: Are you using one of the bitcore sub-projects? I don't see any references to a database in bitcore, or in any of the sub-projects that I looked in, actually.  
> **username_0**: No, I was using the bitcore-node only, but because there were no subproject/module at the moment. They changed quite a bit the code since them, I need to review it again. I'm a bit confused by bitcore (only the library?) and bitcore-node (a full node with DB?), as you have a module for block explorer for bitcore (not bitcore-node) https://github.com/bitpay/bitcore-explorers . The node use a database : https://github.com/bitpay/bitcore-node/blob/master/lib/db.js  Anyway, what I want is the DB key structure, to replicate it on my own  

---

## 1 answers

### Answer by username_1 on 2015-08-06. Score: 2

Bitpay's [bitcore-node](https://github.com/bitpay/bitcore-node) project uses the same datadirectory as Bitcoin Core. You can see this in their sample configuration in their README:

```
var configuration = {
    datadir: '~/.bitcoin',
    network: 'testnet'
};

```

As such, the you can see: [What are the keys used in the blockchain levelDB (ie what are the key:value pairs)?](https://bitcoin.stackexchange.com/questions/28168/what-are-the-keys-used-in-the-blockchain-leveldb-ie-what-are-the-keyvalue-pair) for information on what is in this database. However, bitcore-node does provide another interface for storing extra data about addresses and their balances. This is defined in [this file](https://github.com/bitpay/bitcore-node/blob/v0.2.0/lib/modules/address.js). You have to enable this in your configuration and re-index the blockchain to enable this module, as their README details.

[As these lines show](https://github.com/bitpay/bitcore-node/blob/v0.2.0/lib/modules/address.js#L103-L110), for each output, key-value pairs are added to the leveldb database in this format:

```
key:   [AddressModule.PREFIXES.OUTPUTS, address, timestamp, txid, outputIndex].join('-'),
value: [output.satoshis, script, height].join(':')

```

And, similarly for inputs, this is the format of the key-value pairs:

```
key: [AddressModule.PREFIXES.SPENTS, input.prevTxId, input.outputIndex].join('-'),
value: [txid, j].join(':')

```


---

