https://en.bitcoin.it/w/api.php?action=feedcontributions&user=Oscarguindzberg&feedformat=atomBitcoin Wiki - User contributions [en]2024-03-29T09:01:43ZUser contributionsMediaWiki 1.30.0https://en.bitcoin.it/w/index.php?title=Original_Bitcoin_client/API_calls_list&diff=61506Original Bitcoin client/API calls list2016-08-25T20:39:17Z<p>Oscarguindzberg: </p>
<hr />
<div>Bitcoin API call list (as of version 0.8.0)<br />
<br />
Note: up-to-date API reference can be [https://bitcoin.org/en/developer-reference#bitcoin-core-apis found here].<br />
<br />
== Common operations ==<br />
<br />
=== Listing my bitcoin addresses ===<br />
<br />
Listing the bitcoin [[address|addresses]] in your wallet is easily done via ''listreceivedbyaddress''. It normally lists only addresses which already have received transactions, however you can list all the addresses by setting the first argument to 0, and the second one to true.<br />
<br />
[[accounts explained|Accounts]] are used to organize addresses.<br />
<br />
== Full list ==<br />
<br />
Required arguments are denoted inside &lt; and &gt; Optional arguments are inside [ and ].<br />
<br />
{|class="wikitable"<br />
! Command !! Parameters !! Description !! Requires unlocked wallet? (v0.4.0+)<br />
|-<br />
| <code>addmultisigaddress</code> || <nrequired> <'["key","key"]'> [account] || Add a nrequired-to-sign multisignature address to the wallet. Each key is a bitcoin address or hex-encoded public key. If [account] is specified, assign address to [account]. Returns a string containing the address. || N<br />
|-<br />
| <code>addnode</code> || <node> <add/remove/onetry> || '''version 0.8''' Attempts add or remove <node> from the addnode list or try a connection to <node> once. || N<br />
|-<br />
| <code>backupwallet</code> || <destination> || Safely copies wallet.dat to destination, which can be a directory or a path with filename. || N<br />
|-<br />
| <code>createmultisig</code> || <nrequired> <'["key,"key"]'> || Creates a multi-signature address and returns a json object ||<br />
|-<br />
| <code>createrawtransaction</code> || [{"txid":txid,"vout":n},...] {address:amount,...} || '''version 0.7''' Creates a [[Raw Transactions|raw transaction]] spending given inputs. || N<br />
|-<br />
| <code>decoderawtransaction</code> || <hex string> || '''version 0.7''' Produces a human-readable JSON object for a [[Raw Transactions|raw transaction]]. || N<br />
|-<br />
| <code>dumpprivkey</code> || <bitcoinaddress> || Reveals the private key corresponding to <bitcoinaddress> || Y<br />
|-<br />
| <code>encryptwallet</code> || <passphrase> || Encrypts the wallet with <passphrase>. || N<br />
|-<br />
| <code>getaccount</code> || <bitcoinaddress> || Returns the account associated with the given address. || N<br />
|-<br />
| <code>getaccountaddress</code> || <account> || Returns the current bitcoin address for receiving payments to this account. If <account> does not exist, it will be created along with an associated new address that will be returned. || N<br />
|-<br />
| <code>getaddednodeinfo</code> || <dns> [node] || '''version 0.8''' Returns information about the given added node, or all added nodes<br />
(note that onetry addnodes are not listed here)<br />
If dns is false, only a list of added nodes will be provided,<br />
otherwise connected information will also be available.<br />
|-<br />
| <code>getaddressesbyaccount</code> || <account> || Returns the list of addresses for the given account. || N<br />
|-<br />
| <code>getbalance</code> || [account] [minconf=1] || If [account] is not specified, returns the server's total available balance.<br/>If [account] is specified, returns the balance in the account. || N<br />
|-<br />
| <code>getbestblockhash</code> || || '''version 0.9''' Returns the hash of the best (tip) block in the longest block chain. || N<br />
|-<br />
| <code>getblock</code> || <hash> || Returns information about the block with the given hash. || N<br />
|-<br />
| <code>getblockcount</code> || || Returns the number of blocks in the longest block chain. || N<br />
|-<br />
| <code>getblockhash</code> || <index> || Returns hash of block in best-block-chain at <index>; index 0 is the [[genesis block]] || N<br />
|-<br />
| <code>getblocknumber</code> || || '''Deprecated'''. '''Removed in version 0.7'''. Use getblockcount. || N<br />
|-<br />
| <code>getblocktemplate</code> || [params] || Returns data needed to construct a block to work on. See [[ BIP_0022]] for more info on params.|| N<br />
|-<br />
| <code>getconnectioncount</code> || || Returns the number of connections to other nodes. || N<br />
|-<br />
| <code>getdifficulty</code> || || Returns the proof-of-work difficulty as a multiple of the minimum difficulty. || N<br />
|-<br />
| <code>getgenerate</code> || || Returns true or false whether bitcoind is currently generating hashes || N<br />
|-<br />
| <code>gethashespersec</code> || || Returns a recent hashes per second performance measurement while generating. || N<br />
|-<br />
| <code>getinfo</code> || || Returns an object containing various state info. || N<br />
|-<br />
| <code>getmemorypool</code> || [data] || '''Replaced in v0.7.0 with getblocktemplate, submitblock, getrawmempool''' || N<br />
|-<br />
| <code>getmininginfo</code> || || Returns an object containing mining-related information:<br />
* blocks<br />
* currentblocksize<br />
* currentblocktx<br />
* difficulty<br />
* errors<br />
* generate<br />
* genproclimit<br />
* hashespersec<br />
* pooledtx<br />
* testnet<br />
|| N<br />
|-<br />
| <code>getnewaddress</code> || [account] || Returns a new bitcoin address for receiving payments. If [account] is specified payments received with the address will be credited to [account]. || N<br />
|-<br />
| <code>getpeerinfo</code> || || '''version 0.7''' Returns data about each connected node. || N<br />
|-<br />
| <code>getrawchangeaddress</code> || [account]|| '''version 0.9''' Returns a new Bitcoin address, for receiving change. This is for use with raw transactions, NOT normal use. || N<br />
|-<br />
| <code>getrawmempool</code> || || '''version 0.7''' Returns all transaction ids in memory pool || N<br />
|-<br />
| <code>getrawtransaction</code> || <txid> [verbose=0] || '''version 0.7''' Returns [[Raw Transactions|raw transaction]] representation for given transaction id. || N<br />
|-<br />
| <code>getreceivedbyaccount</code> || [account] [minconf=1] || Returns the total amount received by addresses with [account] in transactions with at least [minconf] confirmations. If [account] not provided return will include all transactions to all accounts. (version 0.3.24) || N<br />
|-<br />
| <code>getreceivedbyaddress</code> || <bitcoinaddress> [minconf=1] || Returns the amount received by <bitcoinaddress> in transactions with at least [minconf] confirmations. It correctly handles the case where someone has sent to the address in multiple transactions. Keep in mind that addresses are only ever used for receiving transactions. Works only for addresses in the local wallet, external addresses will always show 0. || N<br />
|-<br />
| <code>gettransaction</code> || <txid> || Returns an object about the given transaction containing:<br />
* "amount" : total amount of the transaction<br />
* "confirmations" : number of confirmations of the transaction<br />
* "txid" : the transaction ID<br />
* "time" : time associated with the transaction<ref>From block timestamp, unless transaction was already in memory pool then the local time when the client added the transaction to its memory pool</ref>.<br />
* "details" - An array of objects containing:<br />
** "account"<br />
** "address"<br />
** "category"<br />
** "amount"<br />
** "fee"<br />
|| N<br />
|-<br />
| <code>gettxout</code> || <txid> <n> [includemempool=true] || Returns details about an unspent transaction output (UTXO) || N<br />
|-<br />
| <code>gettxoutsetinfo</code> || || Returns statistics about the unspent transaction output (UTXO) set || N<br />
|-<br />
| <code>[[getwork]]</code> || [data] || If [data] is not specified, returns formatted hash data to work on:<br />
* "midstate" : precomputed hash state after hashing the first half of the data<br />
* "data" : block data<br />
* "hash1" : formatted hash buffer for second hash<br />
* "target" : little endian hash target<br />
If [data] is specified, tries to solve the block and returns true if it was successful. <br />
|| N<br />
|-<br />
| <code>help</code> || [command] || List commands, or get help for a command. || N<br />
|-<br />
| <code>importprivkey</code> || <bitcoinprivkey> [label] [rescan=true]|| Adds a private key (as returned by dumpprivkey) to your wallet. This may take a while, as a [[How_to_import_private_keys#Import_Private_key.28s.29|rescan]] is done, looking for existing transactions. '''Optional [rescan] parameter added in 0.8.0.''' Note: There's no need to import public key, as in [[Elliptic_Curve_Digital_Signature_Algorithm|ECDSA]] (unlike RSA) this can be computed from private key. || Y<br />
|-<br />
| <code>invalidateblock</code> || <hash> || Permanently marks a block as invalid, as if it violated a consensus rule.|| N<br />
|-<br />
| <code>keypoolrefill</code> || || Fills the keypool, requires wallet passphrase to be set. || Y<br />
|-<br />
| <code>listaccounts</code> || [minconf=1] || Returns Object that has account names as keys, account balances as values. || N<br />
|-<br />
| <code>listaddressgroupings</code> || || '''version 0.7''' Returns all addresses in the wallet and info used for coincontrol. || N<br />
|-<br />
| <code>listreceivedbyaccount</code> || [minconf=1] [includeempty=false] || Returns an array of objects containing:<br />
* "account" : the account of the receiving addresses<br />
* "amount" : total amount received by addresses with this account<br />
* "confirmations" : number of confirmations of the most recent transaction included<br />
|| N<br />
|-<br />
| <code>listreceivedbyaddress</code> || [minconf=1] [includeempty=false] || Returns an array of objects containing:<br />
* "address" : receiving address<br />
* "account" : the account of the receiving address<br />
* "amount" : total amount received by the address<br />
* "confirmations" : number of confirmations of the most recent transaction included<br />
To get a list of accounts on the system, execute bitcoind listreceivedbyaddress 0 true<br />
|| N<br />
|-<br />
| <code>listsinceblock</code> || [blockhash] [target-confirmations] || Get all transactions in blocks since block [blockhash], or all transactions if omitted. [target-confirmations] intentionally '''does not''' affect the list of returned transactions, but only affects the returned "lastblock" value.[https://github.com/bitcoin/bitcoin/pull/199#issuecomment-1514952] || N<br />
|-<br />
| <code>listtransactions</code> || [account] [count=10] [from=0] || Returns up to [count] most recent transactions skipping the first [from] transactions for account [account]. If [account] not provided it'll return recent transactions from all accounts.<br />
|| N<br />
|-<br />
| <code>listunspent</code> || [minconf=1] [maxconf=999999] || '''version 0.7''' Returns array of unspent transaction inputs in the wallet. || N<br />
|-<br />
| <code>listlockunspent</code> || || '''version 0.8''' Returns list of temporarily unspendable outputs<br />
|-<br />
| <code>lockunspent</code> || <unlock?> [array-of-objects] || '''version 0.8''' Updates list of temporarily unspendable outputs<br />
|-<br />
| <code>move</code> || <fromaccount> <toaccount> <amount> [minconf=1] [comment] || Move from one account in your wallet to another || N<br />
|-<br />
| <code>sendfrom</code> || <fromaccount> <tobitcoinaddress> <amount> [minconf=1] [comment] [comment-to] || <amount> is a real and is rounded to 8 decimal places. Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations. Returns the transaction ID if successful (not in JSON object). || Y<br />
|-<br />
| <code>sendmany</code> || <fromaccount> {address:amount,...} [minconf=1] [comment] || amounts are double-precision floating point numbers || Y<br />
|-<br />
| <code>sendrawtransaction</code> || <hexstring> || '''version 0.7''' Submits [[Raw Transactions|raw transaction]] (serialized, hex-encoded) to local node and network. || N<br />
|-<br />
| <code>sendtoaddress</code> || <bitcoinaddress> <amount> [comment] [comment-to] || <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. || Y<br />
|-<br />
| <code>setaccount</code> || <bitcoinaddress> <account> || Sets the account associated with the given address. Assigning address that is already assigned to the same account will create a new address associated with that account. || N<br />
|-<br />
| <code>setgenerate</code> || <generate> [genproclimit] || <generate> is true or false to turn generation on or off.<br/>Generation is limited to [genproclimit] processors, -1 is unlimited. || N<br />
|-<br />
| <code>settxfee</code> || <amount> || <amount> is a real and is rounded to the nearest 0.00000001 || N<br />
|-<br />
| <code>signmessage</code> || <bitcoinaddress> <message> || Sign a message with the private key of an address. || Y<br />
|-<br />
| <code>signrawtransaction</code> || <hexstring> [{"txid":txid,"vout":n,"scriptPubKey":hex},...] [<privatekey1>,...] || '''version 0.7''' Adds signatures to a [[Raw Transactions|raw transaction]] and returns the resulting raw transaction. || Y/N<br />
|-<br />
| <code>stop</code> || || Stop bitcoin server. || N<br />
|-<br />
| <code>submitblock</code> || <hex data> [optional-params-obj] || Attempts to submit new block to network. || N<br />
|-<br />
| <code>validateaddress</code> || <bitcoinaddress> || Return information about <bitcoinaddress>. || N<br />
|-<br />
| <code>verifymessage</code> || <bitcoinaddress> <signature> <message> || Verify a signed message. || N<br />
|-<br />
| <code>walletlock</code> || || Removes the wallet encryption key from memory, locking the wallet. After calling this method, you will need to call walletpassphrase again before being able to call any methods which require the wallet to be unlocked. || N<br />
|-<br />
| <code>walletpassphrase</code> || <passphrase> <timeout> || Stores the wallet decryption key in memory for <timeout> seconds. || N<br />
|-<br />
| <code>walletpassphrasechange</code> || <oldpassphrase> <newpassphrase> || Changes the wallet passphrase from <oldpassphrase> to <newpassphrase>. || N<br />
<br />
|}<br />
<br />
==Error Codes==<br />
<br />
See [https://github.com/bitcoin/bitcoin/blob/62f2d769e45043c1f262ed45babb70fe237ad2bb/src/rpc/protocol.h#L30 rpcprotocol.h] for the list of error codes and their meanings.<br />
<br />
==See Also==<br />
<br />
* [[Original Bitcoin client]]<br />
* [[Running Bitcoin]]<br />
* [[Protocol specification]]<br />
* [[API reference (JSON-RPC)]]<br />
* [[Lazy_API]]<br />
* [[Elis-API]] - A more detailed version of this page - for developers!<br />
* [http://code.gogulski.com/bitcoin-php/class_bitcoin_client.html PHP BitcoinClient Class Reference]<br />
<br />
==References==<br />
<references /><br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]<br />
<br />
{{Bitcoin Core documentation}}</div>Oscarguindzberghttps://en.bitcoin.it/w/index.php?title=API_reference_(JSON-RPC)&diff=53573API reference (JSON-RPC)2014-12-23T16:14:23Z<p>Oscarguindzberg: Add an alternative bitcoin java json-rpc client library</p>
<hr />
<div>== Controlling Bitcoin ==<br />
<br />
Run ''bitcoind'' or ''bitcoin-qt -server''. You can control it via the command-line bitcoin-cli utility or by [http://json-rpc.org/wiki/specification HTTP JSON-RPC] commands.<br />
<br />
You must create a bitcoin.conf configuration file setting an rpcuser and rpcpassword; see [[Running Bitcoin]] for details.<br />
<br />
Now run:<br />
$ ./bitcoind -daemon<br />
bitcoin server starting<br />
$ ./bitcoin-cli -rpcwait help<br />
# shows the help text<br />
<br />
A [[Original Bitcoin client/API Calls list|list of RPC calls]] will be shown.<br />
<br />
$ ./bitcoin-cli getbalance<br />
2000.00000<br />
<br />
If you are learning the API, it is a very good idea to use the test network (run bitcoind -testnet and bitcoin-cli -testnet).<br />
<br />
== JSON-RPC ==<br />
<br />
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 <br />
[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 'realm' is authenticated, use 'jsonrpc'.<br />
<br />
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.<br />
<br />
Allowing arbitrary machines to access the JSON-RPC port (using the rpcallowip [[Running_Bitcoin|configuration option]]) is dangerous and '''strongly discouraged'''-- access should be strictly limited to trusted machines.<br />
<br />
To access the server you should find a [http://json-rpc.org/wiki/implementations suitable library] for your language.<br />
<br />
== Proper money handling ==<br />
<br />
See the [[Proper Money Handling (JSON-RPC)|proper money handling page]] for notes on avoiding rounding errors when handling bitcoin values.<br />
<br />
== Python ==<br />
<br />
[http://json-rpc.org/wiki/python-json-rpc python-jsonrpc] is the official JSON-RPC implementation for Python.<br />
It automatically generates Python methods for RPC calls.<br />
However, due to its design for supporting old versions of Python, it is also rather inefficient.<br />
[[User:jgarzik|jgarzik]] has forked it as [https://github.com/jgarzik/python-bitcoinrpc Python-BitcoinRPC] and optimized it for current versions.<br />
Generally, this version is recommended.<br />
<br />
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:<br />
<br />
<source lang="python"><br />
from jsonrpc import ServiceProxy<br />
<br />
access = ServiceProxy("http://user:password@127.0.0.1:8332")<br />
access.getinfo()<br />
access.listreceivedbyaddress(6)<br />
#access.sendtoaddress("11yEmxiMso2RsFVfBcCa616npBvGgxiBX", 10)<br />
</source><br />
<br />
The latest version of python-bitcoinrpc has a new syntax.<br />
<source lang="python"><br />
from bitcoinrpc.authproxy import AuthServiceProxy<br />
</source><br />
<br />
== Ruby ==<br />
<br />
<source lang="ruby"><br />
require 'net/http'<br />
require 'uri'<br />
require 'json'<br />
<br />
class BitcoinRPC<br />
def initialize(service_url)<br />
@uri = URI.parse(service_url)<br />
end<br />
<br />
def method_missing(name, *args)<br />
post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json<br />
resp = JSON.parse( http_post_request(post_body) )<br />
raise JSONRPCError, resp['error'] if resp['error']<br />
resp['result']<br />
end<br />
<br />
def http_post_request(post_body)<br />
http = Net::HTTP.new(@uri.host, @uri.port)<br />
request = Net::HTTP::Post.new(@uri.request_uri)<br />
request.basic_auth @uri.user, @uri.password<br />
request.content_type = 'application/json'<br />
request.body = post_body<br />
http.request(request).body<br />
end<br />
<br />
class JSONRPCError < RuntimeError; end<br />
end<br />
<br />
if $0 == __FILE__<br />
h = BitcoinRPC.new('http://user:password@127.0.0.1:8332')<br />
p h.getbalance<br />
p h.getinfo<br />
p h.getnewaddress<br />
p h.dumpprivkey( h.getnewaddress )<br />
# also see: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list<br />
end<br />
</source><br />
<br />
== PHP ==<br />
<br />
The [http://jsonrpcphp.org/ JSON-RPC PHP] library also makes it very easy to connect to Bitcoin. For example:<br />
<br />
<source lang="php"><br />
require_once 'jsonRPCClient.php';<br />
<br />
$bitcoin = new jsonRPCClient('http://user:password@127.0.0.1:8332/');<br />
<br />
echo "<pre>\n";<br />
print_r($bitcoin->getinfo()); echo "\n";<br />
echo "Received: ".$bitcoin->getreceivedbylabel("Your Address")."\n";<br />
echo "</pre>";<br />
</source><br />
<br />
'''Note:''' The jsonRPCClient library uses fopen() and will throw an exception saying "Unable to connect" if it receives a 404 or 500 error from bitcoind. This prevents you from being able to see error messages generated by bitcoind (as they are sent with status 404 or 500). The [https://github.com/aceat64/EasyBitcoin-PHP EasyBitcoin-PHP library] is similar in function to JSON-RPC PHP but does not have this issue.<br />
<br />
== Java ==<br />
<br />
The easiest way to tell Java to use HTTP Basic authentication is to set a default Authenticator:<br />
<br />
<source lang="java"><br />
final String rpcuser ="...";<br />
final String rpcpassword ="...";<br />
<br />
Authenticator.setDefault(new Authenticator() {<br />
protected PasswordAuthentication getPasswordAuthentication() {<br />
return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());<br />
}<br />
});<br />
</source><br />
<br />
Once that is done, [http://json-rpc.org/wiki/implementations any JSON-RPC library for Java] (or ordinary URL POSTs) may be used to communicate with the Bitcoin server.<br />
<br />
Instead to write your wrapper you can use [[Bitcoin-JSON-RPC-Client|this implementation]] or [https://github.com/johannbarbie/BitcoindClient4J this one] .<br />
<br />
== Perl ==<br />
<br />
The JSON::RPC package from CPAN can be used to communicate with Bitcoin. You must set the client's credentials; for example:<br />
<br />
<source lang="perl"><br />
use JSON::RPC::Client;<br />
use Data::Dumper;<br />
<br />
my $client = new JSON::RPC::Client;<br />
<br />
$client->ua->credentials(<br />
'localhost:8332', 'jsonrpc', 'user' => 'password' # REPLACE WITH YOUR bitcoin.conf rpcuser/rpcpassword<br />
);<br />
<br />
my $uri = 'http://localhost:8332/';<br />
my $obj = {<br />
method => 'getinfo',<br />
params => [],<br />
};<br />
<br />
my $res = $client->call( $uri, $obj );<br />
<br />
if ($res){<br />
if ($res->is_error) { print "Error : ", $res->error_message; }<br />
else { print Dumper($res->result); }<br />
} else {<br />
print $client->status_line;<br />
}<br />
</source><br />
<br />
== Go ==<br />
<br />
The [https://github.com/conformal/btcrpcclient btcrpcclient package] can be used to communicate with Bitcoin. You must provide credentials to match the client you are communicating with.<br />
<br />
<source lang="go"><br />
package main<br />
<br />
import (<br />
"github.com/conformal/btcnet"<br />
"github.com/conformal/btcrpcclient"<br />
"github.com/conformal/btcutil"<br />
"log"<br />
)<br />
<br />
func main() {<br />
// create new client instance<br />
client, err := btcrpcclient.New(&btcrpcclient.ConnConfig{<br />
HttpPostMode: true,<br />
DisableTLS: true,<br />
Host: "127.0.0.1:8332",<br />
User: "rpcUsername",<br />
Pass: "rpcPassword",<br />
}, nil)<br />
if err != nil {<br />
log.Fatalf("error creating new btc client: %v", err)<br />
}<br />
<br />
// list accounts<br />
accounts, err := client.ListAccounts()<br />
if err != nil {<br />
log.Fatalf("error listing accounts: %v", err)<br />
}<br />
// iterate over accounts (map[string]btcutil.Amount) and write to stdout<br />
for label, amount := range accounts {<br />
log.Printf("%s: %s", label, amount)<br />
}<br />
<br />
// prepare a sendMany transaction<br />
receiver1, err := btcutil.DecodeAddress("1someAddressThatIsActuallyReal", &btcnet.MainNetParams)<br />
if err != nil {<br />
log.Fatalf("address receiver1 seems to be invalid: %v", err)<br />
}<br />
receiver2, err := btcutil.DecodeAddress("1anotherAddressThatsPrettyReal", &btcnet.MainNetParams)<br />
if err != nil {<br />
log.Fatalf("address receiver2 seems to be invalid: %v", err)<br />
}<br />
receivers := map[btcutil.Address]btcutil.Amount{<br />
receiver1: 42, // 42 satoshi<br />
receiver2: 100, // 100 satoshi<br />
}<br />
<br />
// create and send the sendMany tx<br />
txSha, err := client.SendMany("some-account-label-from-which-to-send", receivers)<br />
if err != nil {<br />
log.Fatalf("error sendMany: %v", err)<br />
}<br />
log.Printf("sendMany completed! tx sha is: %s", txSha.String())<br />
}<br />
</source><br />
<br />
== .NET (C#) ==<br />
The communication with the RPC service can be achieved using the standard http request/response objects.<br />
A library for serialising and deserializing Json will make your life a lot easier:<br />
<br />
Json.Net ( http://james.newtonking.com/json ) is a high performance JSON package for .Net. It is also available via NuGet from the package manager console ( Install-Package Newtonsoft.Json ).<br />
<br />
The following example uses Json.Net:<br />
<br />
<source lang="csharp"><br />
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://localhost.:8332");<br />
webRequest.Credentials = new NetworkCredential("user", "pwd");<br />
/// important, otherwise the service can't desirialse your request properly<br />
webRequest.ContentType = "application/json-rpc";<br />
webRequest.Method = "POST";<br />
<br />
JObject joe = new JObject();<br />
joe.Add(new JProperty("jsonrpc", "1.0"));<br />
joe.Add(new JProperty("id", "1"));<br />
joe.Add(new JProperty("method", Method));<br />
// params is a collection values which the method requires..<br />
if (Params.Keys.Count == 0)<br />
{<br />
joe.Add(new JProperty("params", new JArray()));<br />
}<br />
else<br />
{<br />
JArray props = new JArray();<br />
// add the props in the reverse order!<br />
for (int i = Params.Keys.Count - 1; i >= 0; i--)<br />
{<br />
.... // add the params<br />
}<br />
joe.Add(new JProperty("params", props));<br />
}<br />
<br />
// serialize json for the request<br />
string s = JsonConvert.SerializeObject(joe);<br />
byte[] byteArray = Encoding.UTF8.GetBytes(s);<br />
webRequest.ContentLength = byteArray.Length;<br />
Stream dataStream = webRequest.GetRequestStream();<br />
dataStream.Write(byteArray, 0, byteArray.Length);<br />
dataStream.Close();<br />
<br />
<br />
WebResponse webResponse = webRequest.GetResponse();<br />
<br />
... // deserialze the response<br />
</source><br />
<br />
There is also a wrapper for Json.NET called Bitnet (https://sourceforge.net/projects/bitnet)<br />
implementing Bitcoin API in more convenient way:<br />
<br />
<source lang="csharp"><br />
BitnetClient bc = new BitnetClient("http://127.0.0.1:8332");<br />
bc.Credentials = new NetworkCredential("user", "pass");<br />
<br />
var p = bc.GetDifficulty();<br />
Console.WriteLine("Difficulty:" + p.ToString());<br />
<br />
var inf = bc.GetInfo();<br />
Console.WriteLine("Balance:" + inf["balance"]);<br />
</source><br />
<br />
A more complete library and wrapper for Bitcoin (also for Litecoin and all Bitcoin clones) is [https://github.com/GeorgeKimionis/BitcoinLib BitcoinLib] (https://github.com/GeorgeKimionis/BitcoinLib) which is also available via [https://www.nuget.org/packages/BitcoinLib/ NuGet] from the package manager console (Install-Package BitcoinLib). <br />
<br />
Querying the daemon with [https://github.com/GeorgeKimionis/BitcoinLib BitcoinLib] is as simple as:<br />
<br />
<source lang="csharp"><br />
IBitcoinService bitcoinService = new BitcoinService();<br />
<br />
double networkDifficulty = bitcoinService.GetDifficulty();<br />
decimal myBalance = bitcoinService.GetBalance();<br />
</source><br />
<br />
== Node.js ==<br />
<br />
* [https://github.com/freewil/node-bitcoin node-bitcoin] (npm: bitcoin) <br />
<br />
Example using node-bitcoin:<br />
<br />
<source lang="javascript"><br />
var bitcoin = require('bitcoin');<br />
var client = new bitcoin.Client({<br />
host: 'localhost',<br />
port: 8332,<br />
user: 'user',<br />
pass: 'pass'<br />
});<br />
<br />
client.getDifficulty(function(err, difficulty) {<br />
if (err) {<br />
return console.error(err);<br />
}<br />
<br />
console.log('Difficulty: ' + difficulty);<br />
});<br />
</source><br />
<br />
Example using Kapitalize:<br />
<br />
<source lang='javascript'><br />
var client = require('kapitalize')()<br />
<br />
client.auth('user', 'password')<br />
<br />
client<br />
.getInfo()<br />
.getDifficulty(function(err, difficulty) {<br />
console.log('Dificulty: ', difficulty)<br />
})<br />
</source><br />
<br />
== Command line (cURL) ==<br />
<br />
You can also send commands and see results using [http://curl.haxx.se/ cURL] or some other command-line HTTP-fetching utility; for example:<br />
<br />
<source lang="bash"><br />
curl --user user --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getinfo", "params": [] }' <br />
-H 'content-type: text/plain;' http://127.0.0.1:8332/<br />
</source><br />
<br />
You will be prompted for your rpcpassword, and then will see something like:<br />
<br />
<source lang="javascript"><br />
{"result":{"balance":0.000000000000000,"blocks":59952,"connections":48,"proxy":"","generate":false,<br />
"genproclimit":-1,"difficulty":16.61907875185736,"error":null,"id":"curltest"}<br />
</source><br />
<br />
== Clojure ==<br />
<br />
[https://github.com/aviad/clj-btc clj-btc] is a Clojure wrapper for the bitcoin API.<br />
<br />
<source lang="clojure"><br />
user=> (require '[clj-btc.core :as btc])<br />
nil<br />
user=> (btc/getinfo)<br />
{"timeoffset" 0, "protocolversion" 70001, "blocks" 111908, "errors" "",<br />
"testnet" true, "proxy" "", "connections" 4, "version" 80500,<br />
"keypoololdest" 1380388750, "paytxfee" 0E-8M,<br />
"difficulty" 4642.44443532M, "keypoolsize" 101, "balance" 0E-8M,<br />
"walletversion" 60000}<br />
</source><br />
<br />
== See Also==<br />
<br />
* [[Original_Bitcoin_client/API_Calls_list|API calls list]]<br />
* [[Running Bitcoin]]<br />
* [[Lazy API]]<br />
* [[PHP developer intro]]<br />
* [[Raw_Transactions|Raw Transactions API]]<br />
* [https://gourl.io/bitcoin-payment-gateway-api.html GoUrl Bitcoin PHP Payment API]<br />
* [http://blockchain.info/api/json_rpc_api Web Based JSON RPC interface.]<br />
<br />
[[Category:Technical]]<br />
[[Category:Developer]]<br />
[[zh-cn:API_reference_(JSON-RPC)]]</div>Oscarguindzberghttps://en.bitcoin.it/w/index.php?title=User:Oscarguindzberg&diff=50845User:Oscarguindzberg2014-09-05T03:31:41Z<p>Oscarguindzberg: </p>
<hr />
<div>I am a software developer.<br />
I am currently working on [https://github.com/nimblecoincom/nimblecoinj Nimblecoin] reference implementation, a fork of [https://github.com/bitcoinj/bitcoinj BitcoinJ]<br />
==Contact==<br />
* email: oscar dot guindzberg at gmail <br />
<br />
[[Category:Freelancers]]<br />
[[Category:Freelancers-Software Development]]</div>Oscarguindzberghttps://en.bitcoin.it/w/index.php?title=User:Oscarguindzberg&diff=50600User:Oscarguindzberg2014-08-29T14:02:16Z<p>Oscarguindzberg: Created page with "I am a software developer. I am currently working on [https://github.com/nimblecoincom/nimblecoinj Nimblecoin] reference implementation, a fork of [https://github.com/bitcoinj..."</p>
<hr />
<div>I am a software developer.<br />
I am currently working on [https://github.com/nimblecoincom/nimblecoinj Nimblecoin] reference implementation, a fork of [https://github.com/bitcoinj/bitcoinj BitcoinJ]</div>Oscarguindzberg