Jump to content

Bitcoin JSON-RPC Example


tuheeden
 Share

Recommended Posts

Everyone,

For everyone who may be trying to explore the Bitcoin revolution, I wanted to share my VERY brief example that will hopefully get you started.

Keep in mind that you MUST edit the bitcoin.conf file set these lines:

 # server=1 tells Bitcoin-QT to accept JSON-RPC commands.
 server=1

 # You must set rpcuser and rpcpassword to secure the JSON-RPC api
 rpcuser=test
 rpcpassword=password

Additionally, if you use the bitcoind.exe program, you must start it with these options:

bitcoind.exe -daemon -conf=c:tempbitcoin.conf   (or whereever your .conf file is)

Enjoy:

$URL = "http://127.0.0.1:8332/"
Local $Data1='{"method":"getinfo","params":[],"id":"getinfo"}:'
Dim $obj = ObjCreate ("WinHttp.WinHttpRequest.5.1")
$obj.Open("POST", $URL, false)
$obj.SetCredentials("test","password",0)
$obj.SetRequestHeader("Content-Type", "application/json-rpc")
$obj.Send($Data1)
$oStatusCode = $obj.Status
MsgBox(0,"Response",$oStatusCode & "---" & $obj.ResponseText)

Link to comment
Share on other sites

  • 2 weeks later...

great work!

I changed it up to be able to pull the ballance of the client, which works.

Local $Data1='{"method":"getbalance","params":[]}:'

But I'm not sure how to getthe ballance to include the unconfirmed transactions. Do you know how to pass that option?

 

EDIT: Here is a link, just scroll down to the getballance items:

http://blockchain.info/api/json_rpc_api

Edited by Jazkal
Link to comment
Share on other sites

  • 2 weeks later...

Sorry for the delay on responding, someone I did not have "follow" turned on.

I recommend testing the commands here:

https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list

Only because this may be more current that the Blockchain page (although this is a nice reference page)

Let me test tomorrow and I will post what I find.

Additionally I recommend using the Autoit JSON library found here:

And I will post my sample script using the JSMN library, since it allows passing and receiving of JSON arrays much more easily.

Stay tuned.

Link to comment
Share on other sites

K, sorry for the possibly dumb question.  It takes me a while to get concepts.  I understand bitcoin.  From what I gather, JSON-RPC will allow you to control your wallet remotely?  If so, then can you do things like turn your cellphone into a portable bitcoin wallet?

Link to comment
Share on other sites

OK - Here is a sample script using JSMN library.

#Include "JSMN.au3"
#include <Array.au3>

$URL = "http://127.0.0.1:8332/"
Local $Data1='{"method":"getinfo","params":[],"id":"getinfo"}:'
Dim $obj = ObjCreate ("WinHttp.WinHttpRequest.5.1")
$obj.Open("POST", $URL, false)
$obj.SetCredentials("test","password",0)
$obj.SetRequestHeader("Content-Type", "application/json-rpc")
$obj.Send($Data1)
$oStatusCode = $obj.Status
$results=Jsmn_decode($obj.ResponseText)
$moreresults=Jsmn_ObjTo2DArray($results)
local $test1=Jsmn_ObjGetKeys($results)
Local $Json1=Jsmn_ObjGet($results, $test1[2])
_ArrayDisplay($test1)
_ArrayDisplay($moreresults[1][1])

MsgBox(0,"Response",$Json1 & "+" &$oStatusCode & "---" & $obj.ResponseText)

More to come

Link to comment
Share on other sites

Sorry I missed the question above: Bitcoin and JSON allow you to write your own interface to do things that the "basic" wallet supports, but does not have currently built into the GUI interface.

You could build a completely functional local or remote wallet from AUTOIT if you wanted to (JSON provides you almost unlimited control of the daemon).

That still may be vague, but think of Bitcoin like "electronic cash" and JSON as a way to programatically interact with that wallet.

Link to comment
Share on other sites

That is really cool.  I think things like this being made available to scripting languages like AutoIt will help to boost the public visibility of BitCoin.  I don't have any BitCoins personally (too poor currently) but the idea is revolutionary.  I can't wait to see what cool things could happen with this script.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...