How to make JSON RPC API requests

Introduction

JSON RPC is an alternative to REST for API communication. For some of our endpoints we support JSON RPC as well as REST.

In the subsequent sections we cover JSON RPC request syntax and which of our endpoints support it.

JSON RPC request syntax

API requests using JSON RPC have the following format:

curl -X POST "https://api.syve.ai/v1/rpc" \
    -H "Content-Type: application/json" \
    -d '{
        "method": "JSON_RPC_METHOD",
        "params": {
            "PARAM_1": "VALUE_1",
            ...
            "PARAM_N": "VALUE_N"
        }
    }'

JSON RPC requests must be POST requests.

method is used to specify the endpoint to make a request to.

See the table in "JSON RPC supported endpoints" for possible values for method and corresponding REST endpoint.

params is used to provide query parameters to the request.

The params field must be a JSON object holding the query parameters of your request.

JSON RPC supported endpoints

The table shows all our REST endpoints for which you can also fetch data using JSON RPC syntax. For each endpoint you can see which JSON RPC method you should use.

REST EndpointJSON RPC MethodDocumentation
/v1/price/historical/ohlcv1/getPriceHistoricalOHLChttps://syve.readme.io/reference/price_historical_ohlc
/v1/wallet-api/latest-total-performancev1/getWalletLatestTotalPerformancehttps://syve.readme.io/reference/latest-total-performance
/v1/wallet-api/latest-performance-per-tokenv1/getWalletLatestPerformancePerTokenhttps://syve.readme.io/reference/latest-performance-per-token

JSON RPC response format

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
      ...
    }
}
  • id: This parameter represents a unique identifier for the request, usually used to match the response with its corresponding request.
  • jsonrpc: Indicates the version of the JSON-RPC protocol used. This will always be version 2.0.
  • result: Contains the data returned by the API in response to the request; the actual content will vary depending on the specifics of the API call and the data requested.

JSON RPC error response format

The response of any failed JSON RPC request will contain contain an error object with code and message fields. The code is the status code of the request, and message contains the reason for the error.

Here's an example:

{
    "error": {
        "code": 400,
        "message": "Missing required parameter: token_address"
    },
    "id": 1,
    "jsonrpc": "2.0"
}

For other possible error codes see section "Error Reference" of our documentation.

Example

The example fetches the three most recent daily candles for token 0x6982508145454ce325ddbe47a25d4ec3d2311933.

Request

curl --location --request POST 'https://api.syve.ai/v1/rpc' \
--header 'Content-Type: application/json' \
--data '{
    "method": "v1/getPriceHistoricalOHLC",
    "params": {
        "token_address": "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
        "max_size": 3
    }
}'

Response

{
    "id": 1,
    "jsonrpc": "2.0",
    "result": {
        "data": [
            {
                "date_close": "2024-03-03T23:59:59Z",
                "date_open": "2024-03-03T00:00:00Z",
                "num_trades": 5331,
                "price_close": 5.56724533312634e-06,
                "price_high": 6.143924956331645e-06,
                "price_low": 3.6657401973956833e-06,
                "price_open": 4.397659963622339e-06,
                "timestamp_close": 1709510399,
                "timestamp_open": 1709424000,
                "volume": 63592695.772298865
            },
            {
                "date_close": "2024-03-02T23:59:59Z",
                "date_open": "2024-03-02T00:00:00Z",
                "num_trades": 5376,
                "price_close": 4.397659963622339e-06,
                "price_high": 1.1814564602691062e-05,
                "price_low": 3.7947521228975117e-06,
                "price_open": 4.006846897065098e-06,
                "timestamp_close": 1709423999,
                "timestamp_open": 1709337600,
                "volume": 61639201.58398984
            },
            {
                "date_close": "2024-03-01T23:59:59Z",
                "date_open": "2024-03-01T00:00:00Z",
                "num_trades": 4693,
                "price_close": 4.006846897065098e-06,
                "price_high": 9.647551418347546e-06,
                "price_low": 2.4340510365074858e-06,
                "price_open": 2.7342753385124303e-06,
                "timestamp_close": 1709337599,
                "timestamp_open": 1709251200,
                "volume": 59651238.26855335
            }
        ],
        "token_address": "0x6982508145454ce325ddbe47a25d4ec3d2311933"
    }
}