lian / bitcoin-ruby

bitcoin utils and protocol in ruby.
Other
922 stars 322 forks source link

bitcoin-ruby returns "nil" value for bitcoin-cli calls #254

Closed Rubz2018 closed 6 years ago

Rubz2018 commented 6 years ago

I am a newbie for "bitcoin-ruby" to parse bitcoin blockchain data and found comparatively easier to understand than other parsers. But while testing it, I am having issues to make some bitcoin-cli commands to get this to work. 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 client commands are working :

bitcoinRPC("help",[])

bitcoinRPC("getnewaddress",[])

bitcoinRPC("getchaintips",[])

But following returns "nil" vale :

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

I am sharing the installation environment and versions I have tried till now. Please give your expert guidelines how to fix the issue. Ruby_bitcoin Sheet (1).docx

Thanks in advance for your kind help.

lian commented 6 years ago

not bitcoin-ruby related. check https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Ruby for an RPC client example