user74586: I am new to test "bitcoin-ruby" to parse bitcoin blockchain data. But while testing it, I am having issues to make some bitcoin-cli commands to get this to work. The environment I'm using is :
*Linux version- Ubuntu 16.04 LTS
*Bitcoin Core version- 0.14.2
*Rbenv version- 2.4.3
*Gem version -2.6.14 
*Ruby version-
*Bitcoin-ruby version
*ruby -2.4.3p205 (2017-12-14 revision 61247)
*bitcoin-ruby version- 0.0.15
Here are the codes I am using to parse the data :
require 'bitcoin'
require 'net/http'
require 'json'
RPCUSER = "***"
RPCPASSWORD ="***"

HOST = "localhost"
PORT= 8332

def bitcoinRPC(method,param)
http = Net::HTTP.new(HOST,PORT)
request = Net::HTTP::Post.new('/')
request.basic_auth(RPCUSER,RPCPASSWORD)
request.content_type = 'application/json'
request.body = {method: method, param: param, id: 'jsonrpc'}.to_json
JSON.parse(http.request(request).body)["result"]
end 

The following bitcoin-cli commands are working via bitcoinRPC :
bitcoinRPC("help",[])
bitcoinRPC("getnewaddress",[])
bitcoinRPC("getchaintips",[])
But following returns "nil" vale :
bid = "0000000000000000004bd4aff1966f6df18b1dba6f6ef83a878e526ab31eee73"
bitcoinRPC("getblock",[bid])-> "nil"
Any idea how to fix this issue?
Thanks in advance.

user78801: The above code is only using RPC to Bitcoin Core and bitcoin-ruby is not used.
The problem is the body parameter name when sending the request.
Change param key to params as follow.
request.body = {method: method, params: param, id: 'jsonrpc'}.to_json


74586: <p>I am new to test "bitcoin-ruby" to parse bitcoin blockchain data. But while testing it, I am having issues to make some bitcoin-cli commands to get this to work. The environment I'm using is :</p>

<p>*Linux version- Ubuntu 16.04 LTS
*Bitcoin Core version- 0.14.2
*Rbenv version- 2.4.3
*Gem version -2.6.14 
*Ruby version-
*Bitcoin-ruby version
*ruby -2.4.3p205 (2017-12-14 revision 61247)
*bitcoin-ruby version- 0.0.15</p>

<p>Here are the codes I am using to parse the data :</p>

<pre><code>require 'bitcoin'
require 'net/http'
require 'json'
RPCUSER = "***"
RPCPASSWORD ="***"

HOST = "localhost"
PORT= 8332

def bitcoinRPC(method,param)
http = Net::HTTP.new(HOST,PORT)
request = Net::HTTP::Post.new('/')
request.basic_auth(RPCUSER,RPCPASSWORD)
request.content_type = 'application/json'
request.body = {method: method, param: param, id: 'jsonrpc'}.to_json
JSON.parse(http.request(request).body)["result"]
end 
</code></pre>

<h2>The following bitcoin-cli commands are working via bitcoinRPC :</h2>

<p>bitcoinRPC("help",[])</p>

<p>bitcoinRPC("getnewaddress",[])</p>

<p>bitcoinRPC("getchaintips",[])</p>

<h2>But following returns "nil" vale :</h2>

<p>bid = "0000000000000000004bd4aff1966f6df18b1dba6f6ef83a878e526ab31eee73"
bitcoinRPC("getblock",[bid])-> "nil"</p>

<p>Any idea how to fix this issue?</p>

<p>Thanks in advance.</p>
 78801: <p>The above code is only using RPC to Bitcoin Core and bitcoin-ruby is not used.</p>

<p>The problem is the body parameter name when sending the request.
Change <code>param</code> key to <code>params</code> as follow.</p>

<p><code>request.body = {method: method, params: param, id: 'jsonrpc'}.to_json
</code></p>
