Bitcoin Forum
November 11, 2024, 07:22:54 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin-core. Unhandled rejection RpcError: 404 Not Found when calling getBlockc  (Read 242 times)
educob (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 4


View Profile
September 15, 2018, 10:00:00 AM
Merited by DarkStar_ (2)
 #1

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:

Code:
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:

Code:
W20180915-09:18:15.768(2)? (STDERR) Unhandled rejection RpcError: 404 Not Found
W20180915-09:18:15.768(2)? (STDERR)     at Client.rest (/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/.0.11.1.1vczms8.mxi5++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

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:

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

# Network-related settings:

# Run on the test network instead of the real bitcoin network.
#testnet=0

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

# Connect via a SOCKS5 proxy
#proxy=127.0.0.1:9050

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

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

txindex = 1

# Use as many addnode= settings as you like to connect to specific peers
#addnode=69.164.218.197
#addnode=10.0.0.2:8333

# Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=69.164.218.197
#connect=10.0.0.1:8333

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

# Maximum number of inbound+outbound connections.
#maxconnections=

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

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

# 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)
#rpcbind=<addr>
rpcbind=127.0.0.1

# 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:
rpcuser=xxx
rpcpassword=yyy
#
# 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/rpcuser.py after providing a username:
#
# ./share/rpcuser/rpcuser.py alice
# String to be appended to bitcoin.conf:
# rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
# Your password:
# DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# On client-side, you add the normal user/password pair to send commands:
#rpcuser=alice
#rpcpassword=DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# 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.
#rpcclienttimeout=30

# 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
#rpcallowip=10.1.1.34/255.255.255.0
#rpcallowip=1.2.3.4/24
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96
rpcallowip=127.0.0.1

# as seen in https://bitcoin.stackexchange.com/questions/71800/bitcoin-rpc-econnrefused:
port=8444

# Listen for RPC connections on this TCP port:
rpcport=8332

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

# 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.
#txconfirmtarget=n

# 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.
#keypool=100

# 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.
#paytxfee=0.00

# 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.
#prune=550

# User interface options

# Start Bitcoin minimized
#min=1

# Minimize to the system tray
#minimizetotray=1

# receiving raw transactions.
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333

Thanks.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
September 15, 2018, 07:53:25 PM
Merited by aliashraf (1)
 #2

getblockchaininformation is not a RPC command. You are probably looking for getblockchaininfo.

educob (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 4


View Profile
September 15, 2018, 08:36:48 PM
 #3

Hi.

If you take a look at the library "doc" https://github.com/ruimarinho/bitcoin-core#getblockchaininformationcallback the function is
getBlockchainInformation
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"
educob (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 4


View Profile
September 15, 2018, 09:13:49 PM
Merited by DarkStar_ (2)
 #4

The solution was to insert "rest=1" in bitcoin.conf.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!