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 = "***"

HOST = "localhost"
PORT= 8332

def bitcoinRPC(method,param)
http = Net::HTTP.new(HOST,PORT)
request = Net::HTTP::Post.new('/')
request.content_type = 'application/json'
request.body = {method: method, param: param, id: 'jsonrpc'}.to_json

The following bitcoin-cli commands are working via bitcoinRPC :




But following returns "nil" vale :

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

Any idea how to fix this issue?

Thanks in advance.


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

| improve this answer | |

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.