<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aviad</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aviad"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Aviad"/>
	<updated>2026-05-10T13:11:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=API_reference_(JSON-RPC)&amp;diff=41453</id>
		<title>API reference (JSON-RPC)</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=API_reference_(JSON-RPC)&amp;diff=41453"/>
		<updated>2013-09-29T19:32:52Z</updated>

		<summary type="html">&lt;p&gt;Aviad: Add Clojure&amp;#039;s clj-btc&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Controlling Bitcoin ==&lt;br /&gt;
&lt;br /&gt;
Run &#039;&#039;bitcoind&#039;&#039; or &#039;&#039;bitcoin-qt -server&#039;&#039;. You can control it via the command-line or by [http://json-rpc.org/wiki/specification HTTP JSON-RPC] commands.&lt;br /&gt;
&lt;br /&gt;
You must create a bitcoin.conf configuration file setting an rpcuser and rpcpassword; see [[Running Bitcoin]] for details.&lt;br /&gt;
&lt;br /&gt;
Now run:&lt;br /&gt;
  $ ./bitcoind -daemon&lt;br /&gt;
  bitcoin server starting&lt;br /&gt;
  $ ./bitcoind help&lt;br /&gt;
  # shows the help text&lt;br /&gt;
&lt;br /&gt;
A [[Original Bitcoin client/API Calls list|list of RPC calls]] will be shown.&lt;br /&gt;
&lt;br /&gt;
  $ ./bitcoind getbalance&lt;br /&gt;
  2000.00000&lt;br /&gt;
&lt;br /&gt;
== JSON-RPC ==&lt;br /&gt;
&lt;br /&gt;
Running Bitcoin with the -server argument (or running bitcoind) tells it to function as a [http://json-rpc.org/wiki/specification HTTP JSON-RPC] server, but &lt;br /&gt;
[http://en.wikipedia.org/wiki/Basic_access_authentication Basic access authentication] must be used when communicating with it, and, for security, by default, the server only accepts connections from other processes on the same machine.  If your HTTP or JSON library requires you to specify which &#039;realm&#039; is authenticated, use &#039;jsonrpc&#039;.&lt;br /&gt;
&lt;br /&gt;
Bitcoin supports SSL (https) JSON-RPC connections beginning with version 0.3.14.  See the [[Enabling SSL on original client daemon|rpcssl wiki page]] for setup instructions and a list of all bitcoin.conf configuration options.&lt;br /&gt;
&lt;br /&gt;
Allowing arbitrary machines to access the JSON-RPC port (using the rpcallowip [[Running_Bitcoin|configuration option]]) is dangerous and &#039;&#039;&#039;strongly discouraged&#039;&#039;&#039;-- access should be strictly limited to trusted machines.&lt;br /&gt;
&lt;br /&gt;
To access the server you should find a [http://json-rpc.org/wiki/implementations suitable library] for your language.&lt;br /&gt;
&lt;br /&gt;
== Proper money handling ==&lt;br /&gt;
&lt;br /&gt;
See the [[Proper Money Handling (JSON-RPC)|proper money handling page]] for notes on avoiding rounding errors when handling bitcoin values.&lt;br /&gt;
&lt;br /&gt;
== Python ==&lt;br /&gt;
&lt;br /&gt;
[http://json-rpc.org/wiki/python-json-rpc python-jsonrpc] is the official JSON-RPC implementation for Python.&lt;br /&gt;
It automatically generates Python methods for RPC calls.&lt;br /&gt;
However, due to its design for supporting old versions of Python, it is also rather inefficient.&lt;br /&gt;
[[User:jgarzik|jgarzik]] has forked it as [https://github.com/jgarzik/python-bitcoinrpc Python-BitcoinRPC] and optimized it for current versions.&lt;br /&gt;
Generally, this version is recommended.&lt;br /&gt;
&lt;br /&gt;
While BitcoinRPC lacks a few obscure features from jsonrpc, software using only the ServiceProxy class can be written the same to work with either version the user might choose to install:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
  from jsonrpc import ServiceProxy&lt;br /&gt;
  &lt;br /&gt;
  access = ServiceProxy(&amp;quot;http://user:password@127.0.0.1:8332&amp;quot;)&lt;br /&gt;
  access.getinfo()&lt;br /&gt;
  access.listreceivedbyaddress(6)&lt;br /&gt;
  #access.sendtoaddress(&amp;quot;11yEmxiMso2RsFVfBcCa616npBvGgxiBX&amp;quot;, 10)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ruby ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ruby&amp;quot;&amp;gt;&lt;br /&gt;
require &#039;net/http&#039;&lt;br /&gt;
require &#039;uri&#039;&lt;br /&gt;
require &#039;json&#039;&lt;br /&gt;
&lt;br /&gt;
class BitcoinRPC&lt;br /&gt;
  def initialize(service_url)&lt;br /&gt;
    @uri = URI.parse(service_url)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def method_missing(name, *args)&lt;br /&gt;
    post_body = { &#039;method&#039; =&amp;gt; name, &#039;params&#039; =&amp;gt; args, &#039;id&#039; =&amp;gt; &#039;jsonrpc&#039; }.to_json&lt;br /&gt;
    resp = JSON.parse( http_post_request(post_body) )&lt;br /&gt;
    raise JSONRPCError, resp[&#039;error&#039;] if resp[&#039;error&#039;]&lt;br /&gt;
    resp[&#039;result&#039;]&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def http_post_request(post_body)&lt;br /&gt;
    http    = Net::HTTP.new(@uri.host, @uri.port)&lt;br /&gt;
    request = Net::HTTP::Post.new(@uri.request_uri)&lt;br /&gt;
    request.basic_auth @uri.user, @uri.password&lt;br /&gt;
    request.content_type = &#039;application/json&#039;&lt;br /&gt;
    request.body = post_body&lt;br /&gt;
    http.request(request).body&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  class JSONRPCError &amp;lt; RuntimeError; end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if $0 == __FILE__&lt;br /&gt;
  h = BitcoinRPC.new(&#039;http://user:password@127.0.0.1:8332&#039;)&lt;br /&gt;
  p h.getbalance&lt;br /&gt;
  p h.getinfo&lt;br /&gt;
  p h.getnewaddress&lt;br /&gt;
  p h.dumpprivkey( h.getnewaddress )&lt;br /&gt;
  # also see: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== PHP ==&lt;br /&gt;
&lt;br /&gt;
The [http://jsonrpcphp.org/ JSON-RPC PHP] library also makes it very easy to connect to Bitcoin.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
  require_once &#039;jsonRPCClient.php&#039;;&lt;br /&gt;
  &lt;br /&gt;
  $bitcoin = new jsonRPCClient(&#039;http://user:password@127.0.0.1:8332/&#039;);&lt;br /&gt;
   &lt;br /&gt;
  echo &amp;quot;&amp;lt;pre&amp;gt;\n&amp;quot;;&lt;br /&gt;
  print_r($bitcoin-&amp;gt;getinfo()); echo &amp;quot;\n&amp;quot;;&lt;br /&gt;
  echo &amp;quot;Received: &amp;quot;.$bitcoin-&amp;gt;getreceivedbylabel(&amp;quot;Your Address&amp;quot;).&amp;quot;\n&amp;quot;;&lt;br /&gt;
  echo &amp;quot;&amp;lt;/pre&amp;gt;&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Java ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to tell Java to use HTTP Basic authentication is to set a default Authenticator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  final String rpcuser =&amp;quot;...&amp;quot;;&lt;br /&gt;
  final String rpcpassword =&amp;quot;...&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  Authenticator.setDefault(new Authenticator() {&lt;br /&gt;
      protected PasswordAuthentication getPasswordAuthentication() {&lt;br /&gt;
          return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());&lt;br /&gt;
      }&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once that is done, any JSON-RPC library for Java (or ordinary URL POSTs) may be used to communicate with the Bitcoin server.&lt;br /&gt;
&lt;br /&gt;
== Perl ==&lt;br /&gt;
&lt;br /&gt;
The JSON::RPC package from CPAN can be used to communicate with Bitcoin.  You must set the client&#039;s credentials; for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
  use JSON::RPC::Client;&lt;br /&gt;
  use Data::Dumper;&lt;br /&gt;
   &lt;br /&gt;
  my $client = new JSON::RPC::Client;&lt;br /&gt;
  &lt;br /&gt;
  $client-&amp;gt;ua-&amp;gt;credentials(&lt;br /&gt;
     &#039;localhost:8332&#039;, &#039;jsonrpc&#039;, &#039;user&#039; =&amp;gt; &#039;password&#039;  # REPLACE WITH YOUR bitcoin.conf rpcuser/rpcpassword&lt;br /&gt;
      );&lt;br /&gt;
  &lt;br /&gt;
  my $uri = &#039;http://localhost:8332/&#039;;&lt;br /&gt;
  my $obj = {&lt;br /&gt;
      method  =&amp;gt; &#039;getinfo&#039;,&lt;br /&gt;
      params  =&amp;gt; [],&lt;br /&gt;
   };&lt;br /&gt;
   &lt;br /&gt;
  my $res = $client-&amp;gt;call( $uri, $obj );&lt;br /&gt;
   &lt;br /&gt;
  if ($res){&lt;br /&gt;
      if ($res-&amp;gt;is_error) { print &amp;quot;Error : &amp;quot;, $res-&amp;gt;error_message; }&lt;br /&gt;
      else { print Dumper($res-&amp;gt;result); }&lt;br /&gt;
  } else {&lt;br /&gt;
      print $client-&amp;gt;status_line;&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== .NET (C#) ==&lt;br /&gt;
The communication with rpc service can be achieved using the standard httprequest/response objects.&lt;br /&gt;
A library for serialising and deserialising Json will make your life a lot easier:&lt;br /&gt;
&lt;br /&gt;
* JayRock for .NET 4.0&lt;br /&gt;
* Json.Net for .NET 2.0 and above &lt;br /&gt;
&lt;br /&gt;
The following example uses Json.Net:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(&amp;quot;http://localhost.:8332&amp;quot;);&lt;br /&gt;
 webRequest.Credentials = new NetworkCredential(&amp;quot;user&amp;quot;, &amp;quot;pwd&amp;quot;);&lt;br /&gt;
 /// important, otherwise the service can&#039;t desirialse your request properly&lt;br /&gt;
 webRequest.ContentType = &amp;quot;application/json-rpc&amp;quot;;&lt;br /&gt;
 webRequest.Method = &amp;quot;POST&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
 JObject joe = new JObject();&lt;br /&gt;
 joe.Add(new JProperty(&amp;quot;jsonrpc&amp;quot;, &amp;quot;1.0&amp;quot;));&lt;br /&gt;
 joe.Add(new JProperty(&amp;quot;id&amp;quot;, &amp;quot;1&amp;quot;));&lt;br /&gt;
 joe.Add(new JProperty(&amp;quot;method&amp;quot;, Method));&lt;br /&gt;
 // params is a collection values which the method requires..&lt;br /&gt;
 if (Params.Keys.Count == 0)&lt;br /&gt;
 {&lt;br /&gt;
  joe.Add(new JProperty(&amp;quot;params&amp;quot;, new JArray()));&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
     JArray props = new JArray();&lt;br /&gt;
     // add the props in the reverse order!&lt;br /&gt;
     for (int i = Params.Keys.Count - 1; i &amp;gt;= 0; i--)&lt;br /&gt;
     {&lt;br /&gt;
        .... // add the params&lt;br /&gt;
     }&lt;br /&gt;
     joe.Add(new JProperty(&amp;quot;params&amp;quot;, props));&lt;br /&gt;
     }&lt;br /&gt;
  &lt;br /&gt;
     // serialize json for the request&lt;br /&gt;
     string s = JsonConvert.SerializeObject(joe);&lt;br /&gt;
     byte[] byteArray = Encoding.UTF8.GetBytes(s);&lt;br /&gt;
     webRequest.ContentLength = byteArray.Length;&lt;br /&gt;
     Stream dataStream = webRequest.GetRequestStream();&lt;br /&gt;
     dataStream.Write(byteArray, 0, byteArray.Length);&lt;br /&gt;
     dataStream.Close();&lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     WebResponse webResponse = webRequest.GetResponse();&lt;br /&gt;
     &lt;br /&gt;
     ... // deserialze the response&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is also a wrapper for Json.NET called Bitnet (https://sourceforge.net/projects/bitnet)&lt;br /&gt;
implementing Bitcoin API in more convenient way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;&lt;br /&gt;
     BitnetClient bc = new BitnetClient(&amp;quot;http://127.0.0.1:8332&amp;quot;);&lt;br /&gt;
     bc.Credentials = new NetworkCredential(&amp;quot;user&amp;quot;, &amp;quot;pass&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
     var p = bc.GetDifficulty();&lt;br /&gt;
     Console.WriteLine(&amp;quot;Difficulty:&amp;quot; + p.ToString());&lt;br /&gt;
&lt;br /&gt;
     var inf = bc.GetInfo();&lt;br /&gt;
     Console.WriteLine(&amp;quot;Balance:&amp;quot; + inf[&amp;quot;balance&amp;quot;]);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Node.js ==&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/freewil/node-bitcoin node-bitcoin] (npm: bitcoin) &lt;br /&gt;
&lt;br /&gt;
Example using node-bitcoin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
var bitcoin = require(&#039;bitcoin&#039;);&lt;br /&gt;
var client = new bitcoin.Client({&lt;br /&gt;
  host: &#039;localhost&#039;,&lt;br /&gt;
  port: 8332,&lt;br /&gt;
  user: &#039;user&#039;,&lt;br /&gt;
  pass: &#039;pass&#039;&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
client.getDifficulty(function(err, difficulty) {&lt;br /&gt;
  if (err) {&lt;br /&gt;
    return console.error(err);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  console.log(&#039;Difficulty: &#039; + difficulty);&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example using Kapitalize:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&#039;javascript&#039;&amp;gt;&lt;br /&gt;
var client = require(&#039;kapitalize&#039;)()&lt;br /&gt;
&lt;br /&gt;
client.auth(&#039;user&#039;, &#039;password&#039;)&lt;br /&gt;
&lt;br /&gt;
client&lt;br /&gt;
.getInfo()&lt;br /&gt;
.getDifficulty(function(err, difficulty) {&lt;br /&gt;
  console.log(&#039;Dificulty: &#039;, difficulty)&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command line (cURL) ==&lt;br /&gt;
&lt;br /&gt;
You can also send commands and see results using [http://curl.haxx.se/ cURL] or some other command-line HTTP-fetching utility; for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  curl --user user --data-binary &#039;{&amp;quot;jsonrpc&amp;quot;: &amp;quot;1.0&amp;quot;, &amp;quot;id&amp;quot;:&amp;quot;curltest&amp;quot;, &amp;quot;method&amp;quot;: &amp;quot;getinfo&amp;quot;, &amp;quot;params&amp;quot;: [] }&#039; &lt;br /&gt;
    -H &#039;content-type: text/plain;&#039; http://127.0.0.1:8332/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will be prompted for your rpcpassword, and then will see something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
  {&amp;quot;result&amp;quot;:{&amp;quot;balance&amp;quot;:0.000000000000000,&amp;quot;blocks&amp;quot;:59952,&amp;quot;connections&amp;quot;:48,&amp;quot;proxy&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;generate&amp;quot;:false,&lt;br /&gt;
     &amp;quot;genproclimit&amp;quot;:-1,&amp;quot;difficulty&amp;quot;:16.61907875185736,&amp;quot;error&amp;quot;:null,&amp;quot;id&amp;quot;:&amp;quot;curltest&amp;quot;}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Clojure ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/aviad/clj-btc clj-btc] is a Clojure wrapper for the bitcoin API.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;clojure&amp;quot;&amp;gt;&lt;br /&gt;
user=&amp;gt; (require &#039;[clj-btc.core :as btc])&lt;br /&gt;
nil&lt;br /&gt;
user=&amp;gt; (btc/getinfo)&lt;br /&gt;
{&amp;quot;timeoffset&amp;quot; 0, &amp;quot;protocolversion&amp;quot; 70001, &amp;quot;blocks&amp;quot; 111908, &amp;quot;errors&amp;quot; &amp;quot;&amp;quot;,&lt;br /&gt;
 &amp;quot;testnet&amp;quot; true, &amp;quot;proxy&amp;quot; &amp;quot;&amp;quot;, &amp;quot;connections&amp;quot; 4, &amp;quot;version&amp;quot; 80500,&lt;br /&gt;
 &amp;quot;keypoololdest&amp;quot; 1380388750, &amp;quot;paytxfee&amp;quot; 0E-8M,&lt;br /&gt;
 &amp;quot;difficulty&amp;quot; 4642.44443532M, &amp;quot;keypoolsize&amp;quot; 101, &amp;quot;balance&amp;quot; 0E-8M,&lt;br /&gt;
 &amp;quot;walletversion&amp;quot; 60000}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also==&lt;br /&gt;
&lt;br /&gt;
* [[Original_Bitcoin_client/API_Calls_list|API calls list]]&lt;br /&gt;
* [[Running Bitcoin]]&lt;br /&gt;
* [[Lazy API]]&lt;br /&gt;
* [[PHP developer intro]]&lt;br /&gt;
* [[Raw_Transactions|Raw Transactions API]]&lt;br /&gt;
* [http://blockchain.info/api/json_rpc_api Web Based JSON RPC interface.]&lt;br /&gt;
&lt;br /&gt;
[[Category:Technical]]&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[zh-cn:API_reference_(JSON-RPC)]]&lt;/div&gt;</summary>
		<author><name>Aviad</name></author>
	</entry>
</feed>