solana-with-rpc-optimizations/doc/json-rpc.md

4.8 KiB

Solana JSON RPC API

Solana nodes accept HTTP requests using the JSON-RPC 2.0 specification.

To interact with a Solana node inside a JavaScript application, use the 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

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:

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:
// 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:
// 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:
// 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:
// 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:
// 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}