From c193c7de12f376c8da27050c5c1cdb18d3bcb26c Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 23 Aug 2018 11:48:50 -0600 Subject: [PATCH] Add JSON-RPC API Documentation --- doc/json-rpc.md | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/doc/json-rpc.md b/doc/json-rpc.md index e69de29bb..899e60412 100644 --- a/doc/json-rpc.md +++ b/doc/json-rpc.md @@ -0,0 +1,148 @@ +Solana JSON RPC API +=== + +Solana nodes accept HTTP requests using the [JSON-RPC 2.0](https://www.jsonrpc.org/specification) specification. + +To interact with a Solana node inside a JavaScript application, use the [solana-web3.js](https://github.com/solana-labs/solana-web3.js) library, which gives a convenient interface for the RPC methods. + +RPC Endpoint +--- + +**Default port:** 8899 +eg. http://localhost:8899, 192.168.1.88:8899 + +Methods +--- + +* [confirmTransaction](#confirmtransaction) +* [getAddress](#getaddress) +* [getBalance](#getbalance) +* [getLastId](#getlastid) +* [getTransactionCount](#gettransactioncount) +* [sendTransaction](#sendtransaction) + +Request Formatting +--- + +To make a JSON-RPC request, send an HTTP POST request with a `Content-Type: application/json` header. The JSON request data should contain 4 fields: + +* `jsonrpc`, set to `"2.0"` +* `id`, a unique client-generated identifying integer +* `method`, a string containing the method to be invoked +* `params`, a JSON array of ordered parameter values + +Example using curl: +```bash +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getBalance", "params":["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"]}' 192.168.1.88:8899 +``` + +The response output will be a JSON object with the following fields: + +* `jsonrpc`, matching the request specification +* `id`, matching the request identifier +* `result`, requested data or success confirmation + +Requests can be sent in batches by sending an array of JSON-RPC request objects as the data for a single POST. + +JSON RPC API Reference +--- + +### confirmTransaction +Returns a transaction receipt + +##### Parameters: +* `string` - SIGNATURE of transaction to confirm, as base-58 encoded string + +##### Results: +* `boolean` - transaction status, true if transaction is confirmed + +##### Example: +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"confirmTransaction", "params":["5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW"]}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":true,"id":1} +``` + +--- + +### getBalance +Returns the balance of the account of provided pubkey + +##### Parameters: +* `string` - PUBKEY of account to query, as base-58 encoded string + +##### Results: +* `integer` - quantity, as a signed 64-bit integer i64 + +##### Example: +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getBalance", "params":["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"]}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":0,"id":1} +``` + +--- + +### getLastId +Returns the last entry id from the ledger + +##### Parameters: +None + +##### Results: +* `string` - HASH of last ID, as base-58 encoded string + +##### Example: +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getLastId"}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":"GH7ome3EiwEr7tu9JuTh2dpYWBJK3z69Xm1ZE3MEE6JC","id":1} +``` + +--- + +### getTransactionCount +Returns the current transaction count from the ledger + +##### Parameters: +None + +##### Results: +* `integer` - count, as unsigned 64-bit integer u64 + +##### Example: +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getTransactionCount"}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":268,"id":1} +``` + +--- + +### sendTransaction +Creates new transaction + +##### Parameters: +* `array` - array of octets [u8] containing a fully-signed TRANSACTION + +##### Results: +* `string` - transaction SIGNATURE, as base-58 encoded string + +##### Example: +```bash +// Request +curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"sendTransaction", "params":[[64, 0, 0, 0, 0, 0, 0, 0, 5, 186, 82, 126, 247, 170, 15, 211, 231, 95, 83, 191, 209, 97, 100, 49, 30, 115, 48, 29, 197, 60, 72, 12, 168, 39, 42, 245, 113, 208, 249, 18, 252, 37, 251, 160, 1, 68, 133, 144, 134, 218, 204, 191, 190, 118, 163, 30, 81, 32, 33, 153, 143, 88, 66, 83, 67, 187, 167, 110, 2, 207, 181, 6, 32, 0, 0, 0, 0, 0, 0, 0, 65, 15, 72, 29, 82, 46, 164, 13, 2, 56, 79, 179, 212, 172, 83, 187, 89, 211, 94, 77, 185, 160, 232, 163, 243, 80, 204, 135, 105, 217, 100, 235, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 65, 15, 72, 29, 82, 46, 164, 13, 2, 56, 79, 179, 212, 172, 83, 187, 89, 211, 94, 77, 185, 160, 232, 163, 243, 80, 204, 135, 105, 217, 97, 149, 32, 0, 0, 0, 0, 0, 0, 0, 250, 227, 53, 39, 61, 84, 16, 96, 152, 249, 132, 29, 93, 196, 141, 104, 28, 110, 233, 184, 89, 230, 191, 172, 103, 238, 23, 246, 32, 255, 17, 242, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}' http://localhost:8899 + +// Result +{"jsonrpc":"2.0","result":"5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW","id":1} +``` + +---