<?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=Basinga</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=Basinga"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Basinga"/>
	<updated>2026-05-11T05:46:49Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=CVE-2012-3789&amp;diff=34833</id>
		<title>CVE-2012-3789</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=CVE-2012-3789&amp;diff=34833"/>
		<updated>2013-01-08T21:17:09Z</updated>

		<summary type="html">&lt;p&gt;Basinga: typo s/maga/mega/g&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Multiple DoS Vulnerabilties in Satoshi Bitcoin client ==&lt;br /&gt;
&lt;br /&gt;
Private Release Date: 12-MAY-2012&amp;lt;br /&amp;gt;&lt;br /&gt;
Public Release Date: 08-JAN-2013&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Systems Affected ===&lt;br /&gt;
----------------&lt;br /&gt;
&lt;br /&gt;
- Satoshi Bitcoin Client (Bitcoin-Qt, bitcoind)&amp;lt;br /&amp;gt;&lt;br /&gt;
- All Bitcoin clients that mimic Satoshi client behaviour related to orphan transactions&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Affected Versions ===&lt;br /&gt;
-----------------&lt;br /&gt;
&lt;br /&gt;
- Bitcoin version 0.5.3, released 14 March 2012&amp;lt;br /&amp;gt;&lt;br /&gt;
- Bitcoin version 0.5.3.1 released 16 March 2012&amp;lt;br /&amp;gt;&lt;br /&gt;
- Bitcoin version 0.6.0 released 30 March 2012&amp;lt;br /&amp;gt;&lt;br /&gt;
- Bitcoin version 0.6.1 released 4 May 2012&amp;lt;br /&amp;gt;&lt;br /&gt;
- Bitcoin version 0.6.2 released 8 May 2012&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
--------&lt;br /&gt;
&lt;br /&gt;
This report contains information regarding two new vulnerabilities discovered in May-2012. The more severe one allows a &lt;br /&gt;
connected peer to hang the victim&#039;s client application in less than 20 minutes by sending a stream of specially &lt;br /&gt;
crafted transactions, as a denial-of-service attack.&lt;br /&gt;
&lt;br /&gt;
=== Background ===&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Each peer defines a transaction as &amp;quot;Orphan&amp;quot; if the transaction references a parent transaction (previous output) which is&lt;br /&gt;
neither part of a block in the current best chain, nor it is  in the in-memory transaction pool.&lt;br /&gt;
Before version 0.5.3 of Satoshi Bitcoin client, orphan transactions were stored in a temporary table in memory until the parent transactions could be located in a block or the parent transaction was forwarded by a peer.&lt;br /&gt;
The storage for ophan transaction was unlimited. This feature allowed an attacker to perform a DoS attack by sending transactions continuously until the victim&#039;s virtual memory was filled and the victim&#039;s operating system began trashing. This situation probably leads to the victim&#039;s computer or application to hang. &lt;br /&gt;
The time needed for this DoS attack varies depending on the link bandwidth between the attacker and the victim, and the victim&#039;s RAM size. For an average computer and Internet connection it takes approximately 12 hours.&lt;br /&gt;
&lt;br /&gt;
The vulnerability was discovered by Sergio Demian Lerner and communicated to the Bitcoin.org development team, who developed and applied a patch (https://github.com/bitcoin/bitcoin/pull/911) that was incorporated in version 0.5.3. &lt;br /&gt;
The patch limits the number of orphan transactions that are stored in memory and randomly erases a previous stored transaction on the arrival of a new one, if the memory table becomes full.&lt;br /&gt;
&lt;br /&gt;
Unfortunately the patch is ineffective and allows two new vectors of attack that are more severe than the original attack. The patched version still allows an attacker to fill the victim&#039;s memory with orphan transactions (see vulnerability 1) and it also allows an attacker to hang the victim&#039;s client application (see vulnerability 2) in less than 20 minutes.&lt;br /&gt;
&lt;br /&gt;
=== Vulnerability 1 Details ===&lt;br /&gt;
-----------------------&lt;br /&gt;
&lt;br /&gt;
Orphan transactions are stored in the table mapOrphanTransactions. The patch limits the number of entries to 10000 (constant MAX_ORPHAN_TRANSACTIONS). This number is arbitrary, and the criteria for the selection of the constant is unknown. Because transactions are not limited in size, is easy to create an orphan transaction whose size reaches &lt;br /&gt;
1 megabyte. If the transaction is built with thousands of random inputs (prevouts which are unknown to the victim app) then also the table mapOrphanTransactionsByPrev can fill the entire RAM. Prevouts whose hash is chosen at random would make trashing worse since virtual memory page faults will become inevitable. &lt;br /&gt;
&lt;br /&gt;
Suppose the attacker wants the victim to store 4 Gigabytes of data in virtual memory. Assume a 50 Kb/sec connection bandwidth.&lt;br /&gt;
Then the attack takes approximately 11 hours.&lt;br /&gt;
&lt;br /&gt;
=== Patching vulnerability 1 ===&lt;br /&gt;
------------------------&lt;br /&gt;
&lt;br /&gt;
The application must limit the amount of memory used by tables mapOrphanTransactions and mapOrphanTransactionsByPrev, either by counting the number of bytes used or by limiting the maximum size of each orphan transaction.&lt;br /&gt;
&lt;br /&gt;
Added note: Bitcoin version 0.6.3 and later only store orphan transactions whose size is less than 5000 byles. This limits the amount of memory that mapOrphanTransactions can consume, totalling no more than 50 Mbytes. Since the &amp;quot;map&amp;quot; data structure has a significant overhead when storing a single element, 5000 transactions that link to many random missing previns can force mapOrphanTransactionsByPrev to consume as high as 200 additional megabytes.&lt;br /&gt;
&lt;br /&gt;
Some extra security provisions may be implemented:&lt;br /&gt;
&lt;br /&gt;
* Prioritize orphan transactions that provide a proof of work per input (network protocol must be changed).&lt;br /&gt;
* Limit the amount of transactions that each peer can send depending on the peer connection time  (older peers get more bandwidth)&lt;br /&gt;
&lt;br /&gt;
=== Vulnerability 2 Details ===&lt;br /&gt;
-----------------------&lt;br /&gt;
&lt;br /&gt;
Each time a transaction must be erased from mapOrphanTransactions, all references to parent transactions must be erased from the table mapOrphanTransactionsByPrev too (see EraseOrphanTx()). The method wrongly assumes that the number of &lt;br /&gt;
associations between a parent transaction and its potential childs is low, and so the code iterates through all pairs parent/child until the transaction to be erased is found. Code excerpt:&lt;br /&gt;
&lt;br /&gt;
 BOOST_FOREACH(const CTxIn&amp;amp; txin, tx.vin)&lt;br /&gt;
    {&lt;br /&gt;
        for (multimap&amp;lt;uint256, CDataStream*&amp;gt;::iterator mi = mapOrphanTransactionsByPrev.lower_bound(txin.prevout.hash);&lt;br /&gt;
             mi != mapOrphanTransactionsByPrev.upper_bound(txin.prevout.hash);)&lt;br /&gt;
        {&lt;br /&gt;
            if ((*mi).second == pvMsg)&lt;br /&gt;
                mapOrphanTransactionsByPrev.erase(mi++);&lt;br /&gt;
            else&lt;br /&gt;
                mi++;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each reference to a previous transaction is specified by a prevout, which is a hash of the transaction and an index of the outpoint referred. An attacker can send 10000 transactions that whose inputs refer to the same parent transaction (same hash), but specifying different indexes. Index numbers can be chosen incrementally (from 1 to 1M) since indexes cannot be verified to be out of range for a (still unknown) parent transaction.&lt;br /&gt;
&lt;br /&gt;
The attack is strengthened by the fact that client applications do not check for empty scripts in inputs, so each input size can be as low as 41 bytes. 11K transaction containing 100 fake inputs each is enough to hang a Satoshi client in an Intel Core 2 CPU 4300 running on a local testnet in less than a minute. If a connection of 50 Kb/sec is assumed, then the attack takes less than 20 minutes. Note that only one core of the CPU gets 100% of usage, because the client runs a single thread to process all messages from peers. Simulations were carried on on a local testnet, so the outcome of the attack on a real node (with plenty of peer connections) was not evaluated.&lt;br /&gt;
&lt;br /&gt;
=== Patching vulnerability 2 ===&lt;br /&gt;
------------------------&lt;br /&gt;
&lt;br /&gt;
One possible change is to modify the mapOrphanTransactionsByPrev data structure from:&lt;br /&gt;
&lt;br /&gt;
 multimap&amp;lt;uint256, CDataStream*&amp;gt; mapOrphanTransactionsByPrev;&lt;br /&gt;
&lt;br /&gt;
to:&lt;br /&gt;
&lt;br /&gt;
 map&amp;lt;uint256, map&amp;lt;uint256,CDataStream*&amp;gt; &amp;gt; mapOrphanTransactionsByPrev;&lt;br /&gt;
&lt;br /&gt;
Example new EraseOrphanTx() method (not tested): &lt;br /&gt;
&lt;br /&gt;
 void static EraseOrphanTx(uint256 hash)&lt;br /&gt;
 {&lt;br /&gt;
    if (!mapOrphanTransactions.count(hash))&lt;br /&gt;
        return;&lt;br /&gt;
    const CDataStream* pvMsg = mapOrphanTransactions[hash];&lt;br /&gt;
    CTransaction tx;&lt;br /&gt;
    BOOST_FOREACH(const CTxIn&amp;amp; txin, tx.vin)&lt;br /&gt;
    {&lt;br /&gt;
       mapOrphanTransactionsByPrev[txin.prevout.hash].erase(hash);&lt;br /&gt;
    }&lt;br /&gt;
    mapOrphanTransactions.erase(hash);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Added note: Bitcoin version 0.6.3 and later includes this modification.&lt;br /&gt;
&lt;br /&gt;
=== Disclosure Timeline ===&lt;br /&gt;
-------------------&lt;br /&gt;
&lt;br /&gt;
* 2012-05-12 - Vulnerability reported to Gavin Andressen&lt;br /&gt;
* 2012-05-17 - Gavin Andressen patches ready for review&lt;br /&gt;
* 2012-06-20 - 0.6.3rc1 available for testing&lt;br /&gt;
* 2012-06-25 - Bitcoin version 0.6.3 released, fixing the vulnerabilities.&lt;br /&gt;
* 2013-01-08 - Vulnerability disclosure&lt;br /&gt;
&lt;br /&gt;
=== Credit ===&lt;br /&gt;
------&lt;br /&gt;
&lt;br /&gt;
This vulnerability was discovered by Sergio Demian Lerner, from Certimix.com, who also did&lt;br /&gt;
the vulnerability research and report editing for the public good.&lt;/div&gt;</summary>
		<author><name>Basinga</name></author>
	</entry>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=API_reference_(JSON-RPC)&amp;diff=29996</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=29996"/>
		<updated>2012-08-22T17:14:42Z</updated>

		<summary type="html">&lt;p&gt;Basinga: change ruby code example&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 -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&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;
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;
There are two unofficial node.js modules for interacting with the bitcoin client.&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/freewil/node-bitcoin node-bitcoin] (npm: bitcoin) &lt;br /&gt;
* [https://github.com/Weltschmerz/Kapitalize Kapitalize] (npm: kapitalize)&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;
    console.log(&#039;Error...&#039;);&lt;br /&gt;
    console.log(err);&lt;br /&gt;
    return;&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;
== 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;
&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>Basinga</name></author>
	</entry>
</feed>