5

I want to create a bitcoin explorer using bitcoind. I am using bitcore and insight API for this purpose.

I am already running bitcoind in my local system . I want to connect this running bitcoind with bitcore and use insight-api and UI.

this my bitcore-node.json file:

{
  "network": "testnet",
  "port": 3001,
  "services": [
    "bitcoind",
    "insight-api",
    "insight-ui",
    "web"
  ],
  "servicesConfig": {
    "bitcoind": {
      "spawn": {
        "datadir": "./",
        "exec": "/home/ajit/.nvm/versions/node/v4.8.6/lib/node_modules/bitcore/node_modules/bitcore-node/bin/bitcoind"
      }
    }
  }
}

I have copy-pasted node_module and bitcore-node.json in .bitcoin folder where bitcoin blocks are already downloaded and up to date.

this is my bitcoin.conf

server=1
testnet=1
whitelist=127.0.0.1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
rpcallowip=127.0.0.1
uacomment=bitcore

when i running bitcore i get this logs

ajit@AjitSoman:~/.bitcoin$ bitcored
    [2017-11-17T11:20:14.753Z] info: Using config: /home/ajit/.bitcoin/bitcore-node.json
    [2017-11-17T11:20:14.755Z] info: Using network: testnet
    [2017-11-17T11:20:14.756Z] info: Starting bitcoind
    [2017-11-17T11:20:14.758Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:14.763Z] info: Starting bitcoin process
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:14.796Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:14.797Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:14.853Z] info: Bitcoin Height: 1230668 Percentage: 100.00
    [2017-11-17T11:20:14.862Z] info: Bitcoin Daemon Ready
    [2017-11-17T11:20:14.863Z] info: Starting web
    [2017-11-17T11:20:14.890Z] info: Starting insight-api
    [2017-11-17T11:20:14.891Z] info: Starting insight-ui
    [2017-11-17T11:20:14.892Z] info: Bitcore Node ready
    [2017-11-17T11:20:15.306Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:15.307Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:19.806Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:19.807Z] info: Starting bitcoin process
    [2017-11-17T11:20:19.827Z] warn: Bitcoin process restarted
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:19.848Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:19.848Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:20.326Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:20.326Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:24.848Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:24.849Z] info: Starting bitcoin process
    [2017-11-17T11:20:24.860Z] warn: Bitcoin process restarted
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:24.887Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:24.887Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:25.359Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:25.359Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:29.887Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:29.888Z] info: Starting bitcoin process
    [2017-11-17T11:20:29.906Z] warn: Bitcoin process restarted
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:29.928Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:29.929Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:30.403Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:30.403Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:34.930Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:34.931Z] info: Starting bitcoin process
    [2017-11-17T11:20:34.952Z] warn: Bitcoin process restarted
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:34.971Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:34.971Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:35.450Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:35.451Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:39.972Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
    [2017-11-17T11:20:39.974Z] info: Starting bitcoin process
    [2017-11-17T11:20:39.993Z] warn: Bitcoin process restarted
    Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
    [2017-11-17T11:20:40.008Z] warn: Bitcoin process unexpectedly exited with code: 1
    [2017-11-17T11:20:40.009Z] warn: Restarting bitcoin child process in 5000ms
    [2017-11-17T11:20:40.492Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
    [2017-11-17T11:20:40.492Z] info: ZMQ connected to: tcp://127.0.0.1:28332
    [2017-11-17T11:20:45.010Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf

When i open insight-UI . the UI opens , i got few transactions but did not got blocks list and within 10 sec bitcore stops with this log

[2017-11-17T11:20:50.049Z] info: Starting bitcoin process
[2017-11-17T11:20:50.065Z] warn: Bitcoin process restarted
Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
[2017-11-17T11:20:50.087Z] warn: Bitcoin process unexpectedly exited with code: 1
[2017-11-17T11:20:50.087Z] warn: Restarting bitcoin child process in 5000ms
[2017-11-17T11:20:50.140Z] error: uncaught exception: { Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879
Error
    at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)
    at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)
    at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)
    at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)
    at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)
    at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)
    at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)
    at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)
    at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)
    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40
  message: 'Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879',
  stack: 'Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879\nError\n    at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)\n    at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)\n    at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)\n    at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)\n    at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)\n    at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)\n    at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)\n    at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)\n    at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)\n    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40' }
[2017-11-17T11:20:50.144Z] error: Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879
Error
    at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)
    at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)
    at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)
    at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)
    at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)
    at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)
    at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)
    at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)
    at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)
    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40
[2017-11-17T11:20:50.144Z] info: Beginning shutdown
[2017-11-17T11:20:50.145Z] info: Stopping insight-ui
[2017-11-17T11:20:50.145Z] info: Stopping insight-api
[2017-11-17T11:20:50.146Z] info: Stopping web
[2017-11-17T11:20:50.146Z] info: Stopping bitcoind
[2017-11-17T11:20:50.151Z] info: ::1 "GET /insight-api/blocks?limit=5" 400 29 1.819 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36" 
[2017-11-17T11:20:50.564Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
[2017-11-17T11:20:50.565Z] info: ZMQ connected to: tcp://127.0.0.1:28332
[2017-11-17T11:20:55.087Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
[2017-11-17T11:20:55.089Z] info: Starting bitcoin process
[2017-11-17T11:20:55.096Z] error: Error: Stopping while trying to spawn bitcoind.
    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:905:25
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:676:51
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:726:13
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:52:16
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:264:21
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:44:16
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:723:17
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:167:37
    at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:652:25
    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:887:16
Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
[2017-11-17T11:21:05.149Z] error: Failed to stop services: Error: bitcoind process did not exit
2
+25

it seems to be that there are some bitcoind processes that have zombied out and listening to your port. try to run this command to kill the other processes

killall -9 bitcoind
2

Bitcore has made an implementation of bitcoind and named it as bitcored. The fact that you are running bitcoind first and then bitcored, bitcore is trying to access the same ports as bitcoind. Also the lock file is present in the ~/.bitcoin/testnet3/ folder. Hence the conflict.

You do not need to run bitcoind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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