Difference between revisions of "Elis-API"

From Bitcoin Wiki
Jump to: navigation, search
(Started documenting the API calls with their respective requests, results, and errors in a more readable and understandable way. Still have a long way to go :) -Eli)
 
Line 11: Line 11:
 
<syntaxhighlight lang="javascript">{"method":"listreceivedbyaccount","params":[0],"id":"listreceivedbyaccount"}:</syntaxhighlight>
 
<syntaxhighlight lang="javascript">{"method":"listreceivedbyaccount","params":[0],"id":"listreceivedbyaccount"}:</syntaxhighlight>
  
The Bitcoind server user JSON notation instead of using regular POST parameters which can cause confusions sometime. Note the trailing colon on the post data above.
+
The Bitcoind server uses JSON notation instead of using regular POST parameters which can cause confusions sometime. Note the trailing colon on the post data above.
  
 
The JSON object that is being sent to the server is composed of 3 elements: <tt>method</tt>, <tt>params</tt>, and <tt>id</tt>.
 
The JSON object that is being sent to the server is composed of 3 elements: <tt>method</tt>, <tt>params</tt>, and <tt>id</tt>.

Latest revision as of 01:40, 14 September 2011

Bitcoin API call list (as of version 0.3.20.2) with code samples and returned values.

API Calls

API Calls to JSON-RPC are sent using POST method and parameters are sent as JSON object.

Example Request

When requesting something from the JSON-RPC server the request is sent to the server with the following URL: http://user:pass@localhost:8332/ with post data that looks something like this:

{"method":"listreceivedbyaccount","params":[0],"id":"listreceivedbyaccount"}:

The Bitcoind server uses JSON notation instead of using regular POST parameters which can cause confusions sometime. Note the trailing colon on the post data above.

The JSON object that is being sent to the server is composed of 3 elements: method, params, and id.

method is what method you want to invoke, this is a simple string representing the method you're invoking.

params is the Array parameters that you're sending with the method invocation. Note that these parameters are sent as an Array notation and not Object notation.

id is used by the app requesting, and I usually just send the method name as the ID

Calls List

Required arguments are denoted inside < and > Optional arguments are inside [ and ].



backupwallet

Safely copies wallet.dat to destination, which can be a directory or a path with filename.

Arguments

[0] <Destination> String The destination of the wallet file it will be copied to. This needs to be a valid directory in your file system passed in linux style (forward slashes (/) as separators - linux style, not backward slashes (\) - windows style). The directory must not have a file named wallet.dat otherwise the operation will fail. Example: "d:/wallet-backup/"

Example Request

{"method":"backupwallet","params":["d:/wallet-backup/"],"id":"backupwallet"}:

Result

Success

result = null

{
    "result": null,
    "error": null,
    "id": "backupwallet"
}
Error
{
    "result": null,
    "error": {
        "code": -1,
        "message": "boost::filesystem::copy_file: The file exists: \"C:\\Users\\Eli\\AppData\\Roaming\\Bitcoin\\testnet\\wallet.dat\", \"d:\\wallet-backup\\wallet.dat\""
    },
    "id": "backupwallet"
}

There are other errors that can occur, for example if the directory provided is incorrect.


getaccount

Returns the account associated with the given address.

Arguments

[0] <Bitcoin Address> String The address being checked. Example: "n3CoNg6qBkJauJq5558PrfEHJd8f1emkQZ" (note that this a testnet address), ""

Example Request

{"method":"getaccount","params":["n3CoNg6qBkJauJq5558PrfEHJd8f1emkQZ"],"id":"getaccount"}:

Result

result = String the account that the address is associated with.

Note that some addresses in a bitcoin wallet are not associated with any given account and in those cases the result will be an empty string (i.e. the global account).

Success
{
    "result": "Testnet Faucet",
    "error": null,
    "id": "getaccount"
}
Error

The only time that this method returns an error is when the first argument ([0] Bitcoin Address) is not supplied. In any other case the method will return a successful result with an empty "result" value indicating that the address belongs to the global account, even if no address supplied (i.e. empty string: "") or a bad address altogether (i.e. "eli").

{
    "result": null,
    "error": {
        "code": -1,
        "message": "getaccount <bitcoinaddress>\nReturns the account associated with the given address."
    },
    "id": "getaccount"
}



getaccountaddress

Returns the current bitcoin address for receiving payments to this account.

Arguments

[0] <Account> String The account that you want to get an address for. An empty string is considered as the global account and will return a valid address. Example: "Testnet Faucet", ""

Example Request

{"method":"getaccountaddress","params":["Testnet Faucet"],"id":"getaccountaddress"}:

Result

Success

result = String an address associated with this account.

{
    "result": "mpFrRfLZRWCKzG2VmmxajJLcGpchsYiFQo",
    "error": null,
    "id": "getaccountaddress"
}
Error
{
    "result": null,
    "error": {
        "code": -1,
        "message": "getaccountaddress <account>\nReturns the current bitcoin address for receiving payments to this account."
    },
    "id": "getaccountaddress"
}

This error is only returned if no arguments supplied at all (not even an empty string).



getaddressesbyaccount

Returns the list of addresses for the given account.

Arguments

[0] <Account> String The account that you want to get addresses for. An empty string is considered as the global account and will return a valid address. Example: "Testnet Faucet", ""

Example Request

{"method":"getaddressesbyaccount","params":["Testnet Faucet"],"id":"getaddressesbyaccount"}:

Result

Success

result = Array An array of addresses associated with the account.

{
    "result": [
        "mpFrRfLZRWCKzG2VmmxajJLcGpchsYiFQo",
        "mv97croRs1krPoTXsfoSnxT7YhUn4zECUs"
    ],
    "error": null,
    "id": "getaddressesbyaccount"
}
Error
{
    "result": null,
    "error": {
        "code": -1,
        "message": "getaddressesbyaccount <account>\nReturns the list of addresses for the given account."
    },
    "id": "getaddressesbyaccount"
}

This error is only returned if no arguments supplied at all (not even an empty string).



getbalance

If [Account] is not specified, returns the server's total available balance. If [Account] is specified, returns the balance in the account.

Arguments

[0] [Account] String The account that you want to balance. An empty string is considered as the global account and will return a the balance of the global account. A null value will return the entire balance available for the server. Example: "Testnet Faucet", "", null

[1] [Minimum Confirmations] Integer The minimum confirmations you want to consider when requesting balance. Default value is 1. If 0 is supplied even unconfirmed transactions will be considered and will show in the balance. Example: 1, 0, null

Example Request

{"method":"getbalance","params":[],"id":"getbalance"}:

Result

Success

result = Float A float representing the balance that the account or the server has to it's disposal.

{
    "result": 256.4985,
    "error": null,
    "id": "getbalance"
}
Error

No error should be returned with this method.



getblockbycount

Dumps the block existing at specified height. Note: this is not available in the official release

Arguments

[0] Height