2
'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?

1 Answer 1

2

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' });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.