JSON RPC
Shardeum JSON RPC Documentation
This guide explains how to connect to the Shardeum network through JSON-RPC endpoints, tailored for different user types.
Shardeum provides two main ways to connect to the network:
- Using Public RPC Endpoints - Recommended for most developers, and contributors
- Running Your Own RPC Server - Recommended for exchanges, infrastructure providers, and advanced users
Using Public RPC Endpoints
If you don't want to host your own server, you can connect to the public Shardeum RPC endpoints. This is ideal for most developers and contributors. Visit https://docs.shardeum.org/docs/network/endpoints for the latest network details.
Running Your Own Shardeum RPC Server
This option is recommended for exchanges, infrastructure providers, and enterprise users who require maximum reliability and control.
Prerequisites
You will need to have an archiver and distributor running somewhere. These configs will be provided by a shardeum representative or if you need to run a local devnet you can follow these instructions to run shardus start 10
as well as boot a distributor in MQ mode following the instructions as well.
GitHub Repo: https://github.com/shardeum/ldrpc-docker
Installation
- Pull the Docker Image
- Generate Collector Keys
You'll get:
Important: Share your public key with your Shardeum representative while keeping your secret key secure.
Run the service
Run the service, replacing the env variables with the values provided to you by your contact at Shardeum
Testing Your Server
The JSON-RPC server will be available at http://localhost:8080
and you can now test it with curl:
Run Configuration
The configuration is done through environment variables when running the container. These values should be provided by your shardeum representative:
Variable | Description |
---|---|
ARCHIVER_IP | IP address of the archiver |
ARCHIVER_PUBKEY | Public key of the archiver |
DISTRIBUTOR_IP | IP address of the distributor |
DISTRIBUTOR_PORT | Port address of the distributor |
DISTRIBUTOR_PUBKEY | Public key of the distributor |
COLLECTOR_PUBKEY | Your collector public key |
COLLECTOR_SECRETKEY | Your collector secret key |
COLLECTOR_MODE | Mode of the collector - use MQ (WS deprecated) |
RMQ_HOST | Host of the RabbitMQ server |
RMQ_PORT | Port of the RabbitMQ server |
RMQ_PROTOCOL | Protocol of the RabbitMQ server |
RMQ_USER | User of the RabbitMQ server |
RMQ_PASS | Password of the RabbitMQ server |
RMQ_CYCLES_QUEUE_NAME | Name of the cycles queue |
RMQ_RECEIPTS_QUEUE_NAME | Name of the receipts queue |
RMQ_ORIGINAL_TXS_QUEUE_NAME | Name of the original transactions queue |
CHAIN_ID | The chain ID of the network |
Optional Configuration: For development or testing, you can skip the backup download process using:
-e SKIP_BACKUP_DOWNLOAD=true
. This will prevent the service from downloading a backup of the databases before starting. This can be useful during development or testing, but should not be used in production environments where data integrity is critical.
Healthcheck API
JSON-RPC Server healthcheck API
URL: http://localhost:8080/is-healthy
Sample Response
Healthy:
Response
Unhealthy:
Response
Logging
To enter the Docker container use the command
Logs are stored at:
- Info logs:
~/xyz/pm2/logs/json-rpc-server-out.log
- Error logs:
~/xyz/pm2/logs/json-rpc-server-error.log
Important Note: In the json-rpc-server-out.log
file, if you see messages like Updating NodeList from XXXX and nodelist_update: YYYms
or <N> Healthy Archivers active in the Network
-> This means your JSON-RPC server is active and updating important network information from the network regularly.
Collector Server healthcheck API
URL: http://localhost:4444/is-healthy
Sample Response
Healthy:
Response
Unhealthy:
Response
LOGGING
Logs are stored at:
- Info logs: ~/xyz/pm2/logs/collector-server-out.log
- Error logs: ~/xyz/pm2/logs/collector-server-error.log
Important Note: In the collector-server-out.log
file, if you see messages like:
-
🟢 Verification successful. Updating checkpoint to XXXX
-> This means that the collector is syncing data and also verifying it successfully. Once the XXXX matches latest_cycle_from_explorer - 21 (21 is a threshold from latest cycle to trigger verification of a cycle), it means data verification is caught up with the network. -
[If verbose logging is enabled]
Downloading receipts/originalTxsData/cycles from <X> to <Y>
-> This indicates the API is syncing transaction data. These logs appear mostly during initial sync and become less frequent once syncing stabilizes.
Collector API Server healthcheck API
URL: http://localhost:6101/is-healthy
Sample Response
Healthy:
Response
Unhealthy:
Response
Checking Sync status: During the initial sync, use the /totalData
API to check if the collector is in sync with the network. If totalCycles
, totalTransactions
, and totalOriginalTxs
approximately match what is shown on the explorer, the collector is in sync. Sync speeds vary based on RAM, disk type, and network speed.
Sample Response for /totalData
API:
Response
Important Note: The /totalData
API is resource-intensive and may respond slowly. Avoid frequent requests within a short period to prevent overloading the Collector API Server.
Service Validator healthcheck API
URL: http://localhost:9001/is-healthy
Sample Response
Healthy:
Response
Unhealthy:
Response
Troubleshooting
Debugging
you can attach to the container and check list out the services and their status with pm2
Handling Connection Loss
In rare cases, the Collector Server may lose its connection with RabbitMQ and fail to recover automatically. If this happens, you will see errors in the collector-server-error.log
file, such as:
IllegalOperationError: Channel closed
or Connection error: Error: Channel closed by server: 406 (PRECONDITION-FAILED)
To resolve this issue, restart the Collector Server using the following command:
Error messages and Recovery
You may also encounter the following error messages in the logs:
The last stored cycle counter does not match with the last stored cycle count! Patch the missing cycle data and start the server again!
The last saved receipts of last N cycles data do not match with the distributor data! Clear the DB and start the server again!
The last saved originalTxsData of last N cycles data do not match with the distributor data! Clear the DB and start the server again!
❗ Verification failed for cycle XXXX. Mismatching Receipts[or Transactions]
Cycle XXXX is missing from the database
Identified missing data for cycle: XXXX
Please don't worry if you encounter any of the above error messages. Our systems are designed to automatically recover, sync, and verify any missing data.