Difference between revisions of "NodeCore HTTP API"

From Veriblock Wiki
Jump to: navigation, search
Line 76: Line 76:
 
==== sendcoins ====
 
==== sendcoins ====
  
Note: amount is in Atomic Units, so multiply by 100000000 to get VBK amount.
+
Note: amount is in Atomic Units, so multiply by 100000000 to send VBK amount.
  
 
<pre>
 
<pre>

Revision as of 15:55, 9 December 2019

See: Developer_Guide, GRPC

Overview

NodeCore v0.4.5 introduces an HTTP API to supplement the existing gRPC Admin API. All methods currently available in the gRPC API are also available in the HTTP API.

Usage

By default, the HTTP API is bound to 127.0.0.1:10600. Assuming the defaults are left as is, documentation of the API methods and request/response types can be found at http://localhost:10600/api/docs.

The API follows the JSON-RPC 2.0 Specification. All API requests are made to http://localhost:10600/api. Both request and response will use the application/json content type.

Making a Request

In accordance with the JSON-RPC specification, there is a standard request object format:

{
	"jsonrpc": "2.0",
	"method": "getblocks",
	"params": {...},
	"id": 1
}
  • jsonrpc: Always "2.0" value
  • method: The RPC method name to invoke. Reference the internal API documentation at http://localhost:10600/api/docs#core.Admin for the list of methods available.
  • params: The RPC method-specific request parameters. The internal API documentation describes the request objects for each method.
  • id: A string or number determined by the client to uniquely identify the request. This same id will be used in the response.

Example getinfo

{
 "jsonrpc": "2.0",
 "method": "getinfo",
 "params": {},
 "id": 1
}

Example getblocks

{
 "jsonrpc": "2.0",
 "method": "getblocks",
 "params": {
 "searchLength": 2000,
 "filters": [{index: 349601}]
}

Responses

The standard response object format:

{
    "jsonrpc": "2.0",
    "result": {...},
    "id": 1
}
  • jsonrpc: Always "2.0" value
  • result: The RPC method-specific response object. The internal API documentation describes the response objects for each method.
  • id: The exact string or number supplied by the client in the request object.

Making a Request with curl

getinfo

curl -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "getinfo", "params": {}, "id": 1}' http://127.0.0.1:10600/api

getblockfromindex

curl -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "getblocks", "params": {"searchLength": 1, "filters": [{ "index": "80000" }]}, "id": 1}' http://127.0.0.1:10600/api

sendcoins

Note: amount is in Atomic Units, so multiply by 100000000 to send VBK amount.

curl -H "Content-Type: application/json" --data '{"jsonrpc": "2.0", "method": "sendcoins", "params": {"sourceAddress": "V3TCJ69TfVVELGJi9H5c2m3smAiWeP","amounts": [{"address": "VBasFp1K8LvMWypcC6jFff3TW2JyTn","amount": 10000000}]}, "id": 1}' http://127.0.0.1:10600/api

Configuration

The IP address and port to which the HTTP API is bound can be configured by modifying the nodecore.properties file. The default values are:

http.api.bind.address = 127.0.0.1
http.api.bind.port = 10600

Security

If the rpc.security.password.enabled property in the nodecore.properties file is set to to true, requests to the HTTP API will require the additional header X-VBK-RPC-PASSWORD to be set. The value of this header corresponds to the password defined in the property rpc.security.password in nodecore.properties.


Example:

--header "X-VBK-RPC-PASSWORD: your-password"