solana/doc/json-rpc.md

157 lines
5.1 KiB
Markdown
Raw Normal View History

2018-08-23 10:48:50 -07:00
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
2018-08-23 15:40:18 -07:00
eg. http://localhost:8899, http://192.168.1.88:8899
2018-08-23 10:48:50 -07:00
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.
2018-08-23 15:40:18 -07:00
Definitions
---
* Hash: A SHA-256 hash of a chunk of data.
* Pubkey: The public key of a Ed25519 key-pair.
* Signature: An Ed25519 signature of a chunk of data.
* Transaction: A Solana instruction signed by a client key-pair.
2018-08-23 10:48:50 -07:00
JSON RPC API Reference
---
### confirmTransaction
Returns a transaction receipt
##### Parameters:
2018-08-23 15:40:18 -07:00
* `string` - Signature of Transaction to confirm, as base-58 encoded string
2018-08-23 10:48:50 -07:00
##### Results:
2018-08-23 15:40:18 -07:00
* `boolean` - Transaction status, true if Transaction is confirmed
2018-08-23 10:48:50 -07:00
##### 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
2018-08-23 15:40:18 -07:00
Returns the balance of the account of provided Pubkey
2018-08-23 10:48:50 -07:00
##### Parameters:
2018-08-23 15:40:18 -07:00
* `string` - Pubkey of account to query, as base-58 encoded string
2018-08-23 10:48:50 -07:00
##### Results:
2018-08-23 15:40:18 -07:00
* `integer` - quantity, as a signed 64-bit integer
2018-08-23 10:48:50 -07:00
##### 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
2018-08-23 15:40:18 -07:00
Returns the last entry ID from the ledger
2018-08-23 10:48:50 -07:00
##### Parameters:
None
##### Results:
2018-08-23 15:40:18 -07:00
* `string` - the ID of last entry, a Hash as base-58 encoded string
2018-08-23 10:48:50 -07:00
##### 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
2018-08-23 15:40:18 -07:00
Returns the current Transaction count from the ledger
2018-08-23 10:48:50 -07:00
##### Parameters:
None
##### Results:
2018-08-23 15:40:18 -07:00
* `integer` - count, as unsigned 64-bit integer
2018-08-23 10:48:50 -07:00
##### 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:
2018-08-23 15:40:18 -07:00
* `array` - array of octets containing a fully-signed Transaction
2018-08-23 10:48:50 -07:00
##### Results:
2018-08-23 15:40:18 -07:00
* `string` - Transaction Signature, as base-58 encoded string
2018-08-23 10:48:50 -07:00
##### 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}
```
---