401 Unauthorized when connecting via JSON-RPC

+2 votes

I'm trying to build a Ruby client for the JSON-RPC service, but I can't seem to connect. I'm taking the username and password from the `multichain.conf` file, and I've added `rpcallowip=my-ip-address` to the same file. After restarting the client, I'm getting a 401 error.

My multichain.conf file looks like this:


And I'm trying to connect with the following url:


 Any ideas where I'm going wrong?

asked Jan 5, 2016 by Stuart Harrison

3 Answers

+2 votes

Hi, you might want to take a look at one of the libraries that has been built for connecting to Bitcoin Core, since MultiChain's API works in exactly the same way: https://github.com/sinisterchipmunk/bitcoin-client

Also make sure you restart MultiChain after setting up the configuration in multichain.conf

answered Jan 5, 2016 by MultiChain
OK, I can get in via the Bitcoin Client. I must be missing something my end then. Will report back if I find anything. Thanks!
+3 votes

Hey I just started building an explorer for my new test blockchain, feel free to look at the source on Github, I would appreciate a shoutout in your code back to my repo or git username ;)


Specifically, take a look at services/bitcoin_rpc.rb @ https://github.com/Padchain/Explorer/blob/master/app/services/bitcoin_rpc.rb

If you go with this implementation you can query your data as shown:

@info = BitcoinRpc.new('http://multichainrpc:' + ENV['PADCHAIN_NODE_KEY'] + '@' + ENV['PADCHAIN_NODE_ADDRESS'] + ':6306/').getinfo


Also be sure to check multichain.conf/params.dat to whitelist the IP you are connecting from. By default, Multichain only allows RPC calls from localhost.

answered Jan 7, 2016 by mreichardt
Cool, thanks. That's the approach we took in the end. I was using the json-rpc gem to connect, but just connecting via any old HTTP library worked.
Great to help! Please upvote me or select as answer :). Happy developing.
+1 vote

I got the same 401 error. 

This is how I resolve this 401 problem:


In short, there are 2 multichain.conf files.

I allow access by modifying ~/.multichain/multichain.conf


The rpcuser and rpcpassword will be generated automatically in ~/.multichain/chain1/multichain.conf, for example:


After putting rpcuser and rpcpassword to Basic Auth. 
I am able to send JSON-RPC successfully.
answered Sep 29, 2018 by ywlee