JSON-RPC
CROSS Chain: Interacting with the Blockchain via JSON-RPC
To interact with CROSS Chain, you need to utilize JSON-RPC to handle transactions with the network. This protocol allows you to send transactions to the CROSS Chain network, retrieve data, and more.
1. What is JSON-RPC?
JSON-RPC is a remote procedure call (RPC) protocol that provides a simple and lightweight way to interact with blockchain networks. The protocol is stateless and can operate across different environments using JSON (RFC 4627) for data formatting. It is flexible and can work over various transport layers like HTTP and sockets.
CROSS Chain implements JSON-RPC to provide developers with access to blockchain data, transaction processing, and other features.
2. CROSS Chain JSON-RPC API Specification
CROSS Chain is fully compatible with the Ethereum JSON-RPC specification. This means any Ethereum-compatible tool can also work with CROSS Chain.
- Full spec: Ethereum API Spec
Network Endpoints
Mainnet
Testnet
3. JSON-RPC Request Structure
Request Format
{
"jsonrpc": "2.0",
"method": "method_name",
"params": [param1, param2],
"id": 1
}
Response Format
Success:
{
"jsonrpc": "2.0",
"id": 1,
"result": { ... }
}
Error:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32000,
"message": "Error message",
"data": "Details"
}
}
4. Example JSON-RPC Method Calls
4.1 Get Block by Number
{
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": ["latest", true],
"id": 1
}
4.2 Get Transaction by Hash
{
"jsonrpc": "2.0",
"method": "eth_getTransactionByHash",
"params": ["0xd7b510d535e8f107..."],
"id": 1
}
4.3 Get Account Balance
{
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": ["0xe5dFec1e7Ca7AA90...", "latest"],
"id": 1
}
4.4 Send Transaction
{
"jsonrpc": "2.0",
"method": "eth_sendTransaction",
"params": [{
"from": "0x...",
"to": "0x...",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0xde0b6b3a7640000",
"data": "0x"
}],
"id": 1
}
4.5 Smart Contract Call
{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6b175474e89094c44da98b954eedeac495271d0f",
"data": "0x70a0823100000000..."
},
"latest"
],
"id": 1
}
5. Interacting with CROSS Chain using curl
Get Latest Block Number (Mainnet)
curl -X POST https://mainnet.cross-nexus.com \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Get Account Balance (Testnet)
curl -X POST https://testnet.cross-nexus.com \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x...", "latest"],"id":1}'
6. Commonly Used JSON-RPC Methods
Method | Description |
---|---|
eth_blockNumber | Returns the number of the most recent block |
eth_getBalance | Returns balance of the account at given address |
eth_getBlockByNumber | Returns information about a block by number |
eth_getBlockByHash | Returns block info using block hash |
eth_getTransactionCount | Returns the number of transactions from address |
eth_getTransactionByHash | Returns transaction details by hash |
eth_getTransactionReceipt | Returns transaction receipt |
eth_sendRawTransaction | Submits a raw, signed transaction |
eth_call | Calls a smart contract function without state changes |
eth_estimateGas | Estimates gas required for a transaction |
eth_getLogs | Returns logs based on filter object |
net_version | Returns current network ID |
7. JSON-RPC Error Codes
Code | Message | Description |
---|---|---|
-32700 | Parse error | Invalid JSON |
-32600 | Invalid Request | The JSON sent is not a valid request |
-32601 | Method not found | Method does not exist |
-32602 | Invalid params | Invalid method parameters |
-32603 | Internal error | Internal JSON-RPC error |
-32000 to -32099 | Server error | Generic server-side errors |
8. Security Considerations
- Always use HTTPS when communicating over public networks
- Limit API access when exposing nodes to the internet
- Perform sensitive operations like private key handling offline
- Validate data before sending transactions
- Set appropriate gas limits for contract interaction
Updated 26 days ago