Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: educob on September 15, 2018, 10:00:00 AM

Title: Bitcoin-core. Unhandled rejection RpcError: 404 Not Found when calling getBlockc
Post by: educob on September 15, 2018, 10:00:00 AM
Please help me. I have lost a lot of time with this.

I am running a fully synchronized bitcoin-core mainnet node. I run this code to access the node:

import Client from 'bitcoin-core'
let client = new Client( { username: 'xxx', password: 'yyy', port: 8332})
client.getBlockchainInformation().then( res => console.log("res: ", res))

I have also tried without the port attribute and with port:8444. I get these errors:

W20180915-09:18:15.768(2)? (STDERR) Unhandled rejection RpcError: 404 Not Found
W20180915-09:18:15.768(2)? (STDERR)     at (/home/r2d2/vue/txxx/node_modules/bitcoin-core/dist/src/parser.js:117:13)
W20180915-09:18:15.769(2)? (STDERR)     at apply (/home/r2d2/vue/txxx/node_modules/lodash/lodash.js:475:27)
W20180915-09:18:15.769(2)? (STDERR)     at Client.wrapper (/home/r2d2/vue/txxx/node_modules/lodash/lodash.js:5337:16)
W20180915-09:18:15.769(2)? (STDERR)     at Request.self.callback (/home/r2d2/vue/txxx/node_modules/request/request.js:185:22)
W20180915-09:18:15.769(2)? (STDERR)     at emitTwo (events.js:131:20)
W20180915-09:18:15.769(2)? (STDERR)     at Request.emit (events.js:214:7)
W20180915-09:18:15.769(2)? (STDERR)     at Request.<anonymous> (/home/r2d2/vue/txxx/node_modules/request/request.js:1161:10)
W20180915-09:18:15.769(2)? (STDERR)     at emitOne (events.js:116:13)
W20180915-09:18:15.769(2)? (STDERR)     at Request.emit (events.js:211:7)
W20180915-09:18:15.770(2)? (STDERR)     at IncomingMessage.<anonymous> (/home/r2d2/vue/txxx/node_modules/request/request.js:1083:12)
W20180915-09:18:15.770(2)? (STDERR)     at Object.onceWrapper (events.js:313:30)
W20180915-09:18:15.770(2)? (STDERR)     at emitNone (events.js:111:20)
W20180915-09:18:15.770(2)? (STDERR)     at IncomingMessage.emit (events.js:208:7)
W20180915-09:18:15.770(2)? (STDERR)     at endReadableNT (_stream_readable.js:1064:12)
W20180915-09:18:15.770(2)? (STDERR)     at _combinedTickCallback (internal/process/next_tick.js:138:11)
W20180915-09:18:15.770(2)? (STDERR) From previous event:
W20180915-09:18:15.770(2)? (STDERR)     at Client.getBlockchainInformation (/home/r2d2/vue/txxx/node_modules/bitcoin-core/dist/src/index.js:238:69)
W20180915-09:18:15.770(2)? (STDERR)     at Promise.asyncApply (server/jobs.js:24:10)
W20180915-09:18:15.771(2)? (STDERR)     at /home/r2d2/.meteor/packages/promise/.

Receiving rawTx and rawBlock notifications via zmq works ok cause, for a change, I found proper doc: Streaming transactions from bitcoind via ZeroMQ.

My bitcoin.conf file is:

## bitcoin.conf configuration file. Lines beginning with # are comments.

# Network-related settings:

# Run on the test network instead of the real bitcoin network.

# Run a regression test network
# when we don't need it to run as a daemon.

# Connect via a SOCKS5 proxy

# Bind to given address and always listen on it. Use [host]:port notation for IPv6

# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6

txindex = 1

# Use as many addnode= settings as you like to connect to specific peers

# Alternatively use as many connect= settings as you like to connect ONLY to specific peers

# Listening mode, enabled by default except when 'connect' is being used

# Maximum number of inbound+outbound connections.

# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)

# server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands

# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6.
# This option can be specified multiple times (default: bind to all interfaces)

# If no rpcpassword is set, rpc cookie auth is sought. The default `-rpccookiefile` name
# is .cookie and found in the `-datadir` being used for bitcoind. This option is typically used
# when the server and client are run as the same user.
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC api. The first
# method(DEPRECATED) is to set this pair for the server and client:
# The second method `rpcauth` can be added to server startup argument. It is set at intialization time
# using the output from the script in share/rpcuser/ after providing a username:
# ./share/rpcuser/ alice
# String to be appended to bitcoin.conf:
# rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
# Your password:
# On client-side, you add the normal user/password pair to send commands:
# You can even add multiple entries of these to the server conf file, and client can use any of them:
# rpcauth=bob:b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99

# How many seconds bitcoin will wait for a complete RPC HTTP request.
# after the HTTP connection is established.

# By default, only RPC connections from localhost are allowed.
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,
# either as a single IPv4/IPv6 or with a subnet specification.

# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
# because the rpcpassword is transmitted over the network unencrypted.

# server=1 tells Bitcoin-Qt to accept JSON-RPC commands.
# it is also read by bitcoind to determine if RPC should be enabled

# as seen in

# Listen for RPC connections on this TCP port:

# You can use Bitcoin or bitcoind to send commands to Bitcoin/bitcoind
# running on another host using this option:

# Create transactions that have enough fees so they are likely to begin confirmation within n blocks (default: 6).
# This setting is over-ridden by the -paytxfee option.

# Miscellaneous options

# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.

# Pay an optional transaction fee every time you send bitcoins.  Transactions with fees
# are more likely than free transactions to be included in generated blocks, so may
# be validated sooner.

# Enable pruning to reduce storage requirements by deleting old blocks.
# This mode is incompatible with -txindex and -rescan.
# 0 = default (no pruning).
# 1 = allows manual pruning via RPC.
# >=550 = target to stay under in MiB.

# User interface options

# Start Bitcoin minimized

# Minimize to the system tray

# receiving raw transactions.


Title: Re: Bitcoin-core. Unhandled rejection RpcError: 404 Not Found when calling getBlockc
Post by: achow101 on September 15, 2018, 07:53:25 PM
getblockchaininformation is not a RPC command. You are probably looking for getblockchaininfo.

Title: Re: Bitcoin-core. Unhandled rejection RpcError: 404 Not Found when calling getBlockc
Post by: educob on September 15, 2018, 08:36:48 PM

If you take a look at the library "doc" ( the function is
If I use getBlockchainInfo I get "TypeError: client.getblockchaininfo is not a function"
Using "bitcoin-cli getblockchaininfo" external command, works perfectly.

I am surprised not to find a single complete example using the client.

Using postman with url localhost:8332/rest/tx/b4dd08f32be15d96b7166fd77afd18aece7480f72af6c9c7f9c5cbeb01e686fe.json and body parameters: username=xxx & password=yyy I get the same: "404 Not Found"

Title: Re: Bitcoin-core. Unhandled rejection RpcError: 404 Not Found when calling getBlockc
Post by: educob on September 15, 2018, 09:13:49 PM
The solution was to insert "rest=1" in bitcoin.conf.