<p>Chain accepts parameter <code>db</code>, which can have multiple backends.
By default it will be stored in memory. So this tip is coming from memory.</p>

<p>If you want to store it to File(For example full node stores it in PREFIX/chain) you need to pass <code>db</code> with backend(ldb for example) and specify either <code>prefix</code> or <code>location</code>.</p>

<p><code>prefix</code> stands for general directory where chain and wallet will be stored.
<code>location</code> specifies DB directly.</p>

<p>So if we wanted to store this db in <code>/tmp/testnet-1/chain.ldb</code> We could specify:</p>

<p><code>const chain = new Chain({
  network: 'main',
  db: 'leveldb',
  location: '/tmp/testnet-1/chain',
});
</code>
or</p>

<p><code>const chain = new Chain({
  network: 'main',
  db: 'leveldb',
  prefix: '/tmp/testnet-1'
});
</code></p>

CC BY-SA 3.0
2017-08-09T07:41:33.503Z
2017-08-09T07:41:33.503Z
Node
<pre><code>'use strict';

const Chain = require('bcoin/lib/blockchain/chain');

const chain = new Chain({
  network: 'main'
});

(async () =&gt; {
  await chain.open();
  console.log(chain.tip);
})();
</code></pre>

<p>The result is:</p>

<pre><code>{ hash: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
  version: '00000001',
  prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
  merkleRoot: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
  time: 1231006505,
  bits: 486604799,
  nonce: 2083236893,
  height: 0,
  chainwork: '0000000000000000000000000000000000000000000000000000000100010001' }
</code></pre>

<p>Where is the database for this located?</p>

<blockchain><blockchain-data-storage><bcoin>
Bcoin - chain database location
tuxcanfly
# Bcoin - chain database location

(Asked by: username_0 on 2017-08-09)

'use strict';

const Chain = require('bcoin/lib/blockchain/chain');

const chain = new Chain({
  network: 'main'
});

(async () => {
  await chain.open();
  console.log(chain.tip);
})();

The result is:
{ hash: '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f',
  version: '00000001',
  prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
  merkleRoot: '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b',
  time: 1231006505,
  bits: 486604799,
  nonce: 2083236893,
  height: 0,
  chainwork: '0000000000000000000000000000000000000000000000000000000100010001' }

Where is the database for this located?

**Tags:** blockchain, blockchain-data-storage, bcoin


---

## 1 answers

### Answer by username_1 on 2017-08-09. Score: 2 | Accepted answer

Chain accepts parameter `db`, which can have multiple backends.
By default it will be stored in memory. So this tip is coming from memory.

If you want to store it to File(For example full node stores it in PREFIX/chain) you need to pass `db` with backend(ldb for example) and specify either `prefix` or `location`.

`prefix` stands for general directory where chain and wallet will be stored.
`location` specifies DB directly.

So if we wanted to store this db in `/tmp/testnet-1/chain.ldb` We could specify:

`const chain = new Chain({
network: 'main',
db: 'leveldb',
location: '/tmp/testnet-1/chain',
});`
or

`const chain = new Chain({
network: 'main',
db: 'leveldb',
prefix: '/tmp/testnet-1'
});`


---

