Skip to content

API Overview

Cloud Service provides multiple APIs for interacting with the blockchain, building applications, and integrating with services.

Available APIs

APIProtocolUse CasePort
JSON-RPCHTTP POSTNode management, wallet operations16180
REST APIHTTP GETBlockchain data, transactions16180
WebSocketWSReal-time notifications16181
ZeroMQZMQEvent streamingConfigurable

Quick Start

Enable APIs

Add to your cs.conf:

ini
# Enable JSON-RPC
server=1
rpcuser=your_username
rpcpassword=your_password
rpcport=16180
rpcallowip=127.0.0.1

# Enable REST API
rest=1

# Enable WebSocket
wsport=16181

# Enable ZeroMQ
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
zmqpubhashblock=tcp://127.0.0.1:28334

Authentication

All API requests require authentication:

bash
# Basic authentication
curl -u your_username:your_password \
     -H "Content-Type: application/json" \
     -d '{"jsonrpc": "1.0", "id": "curl", "method": "getblockchaininfo", "params": []}' \
     http://localhost:16180/

JSON-RPC API

The JSON-RPC API provides full access to node and wallet functionality.

Request Format

json
{
    "jsonrpc": "1.0",
    "id": "request_id",
    "method": "method_name",
    "params": [param1, param2, ...]
}

Response Format

json
{
    "result": { ... },
    "error": null,
    "id": "request_id"
}

Example: Get Blockchain Info

bash
curl -u user:password \
     -H "Content-Type: application/json" \
     -d '{"jsonrpc": "1.0", "id": "1", "method": "getblockchaininfo", "params": []}' \
     http://localhost:16180/

Response:

json
{
    "result": {
        "chain": "main",
        "blocks": 524288,
        "headers": 524288,
        "bestblockhash": "0000000000000000000...",
        "difficulty": 12345678.90123456,
        "mediantime": 1234567890,
        "verificationprogress": 0.999999,
        "chainwork": "0000000000000000000000000000000000000000000000000000000000000000",
        "pruned": false
    },
    "error": null,
    "id": "1"
}

REST API

The REST API provides simple HTTP endpoints for blockchain data.

Endpoints

EndpointDescription
/rest/chaininfoBlockchain information
/rest/block/<hash>Block details
/rest/tx/<txid>Transaction details
/rest/address/<address>Address information
/rest/mempool/infoMempool information
/rest/mempool/contentsMempool transactions

Example: Get Block

bash
curl http://localhost:16180/rest/block/0000000000000000000.json

Example: Get Transaction

bash
curl http://localhost:16180/rest/tx/txid.json

WebSocket API

Real-time notifications for blockchain events.

Connection

javascript
const ws = new WebSocket('ws://localhost:16181');

ws.on('open', () => {
    console.log('Connected to Cloud Service WebSocket');
});

ws.on('message', (data) => {
    console.log('Received:', JSON.parse(data));
});

Subscriptions

json
// Subscribe to new blocks
{"action": "subscribe", "channel": "new-blocks"}

// Subscribe to address transactions
{"action": "subscribe", "channel": "address-tx", "address": "csc1q..."}

// Subscribe to mempool
{"action": "subscribe", "channel": "mempool"}

ZeroMQ

Event streaming for high-throughput applications.

Configuration

ini
# cs.conf
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
zmqpubhashblock=tcp://127.0.0.1:28334
zmqpubrawtx=tcp://127.0.0.1:28335

Python Example

python
import zmq
import struct

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect("tcp://127.0.0.1:28332")
socket.setsockopt(zmq.SUBSCRIBE, b"rawtx")

while True:
    message = socket.recv_multipart()
    topic = message[0]
    body = message[1]
    print(f"Received {topic}: {body[:20].hex()}...")

SDKs and Libraries

Official SDKs

LanguagePackageRepository
JavaScript@cscoin/sdkGitHub
Pythoncs-pythonGitHub
Gogo-cscoinGitHub
Rustcs-rustGitHub

JavaScript Example

javascript
const { Cloud Service } = require('@cscoin/sdk');

const csc = new Cloud Service({
    host: 'localhost',
    port: 16180,
    user: 'your_username',
    pass: 'your_password'
});

// Get blockchain info
const info = await csc.getBlockchainInfo();
console.log(info);

// Send transaction
const txid = await csc.sendToAddress('csc1q...', 10.5);
console.log(txid);

Python Example

python
from cscoin import Cloud Service

csc = Cloud Service(
    host='localhost',
    port=16180,
    user='your_username',
    password='your_password'
)

# Get blockchain info
info = csc.get_blockchain_info()
print(info)

# Send transaction
txid = csc.send_to_address('csc1q...', 10.5)
print(txid)

Rate Limiting

EndpointLimit
JSON-RPC100 requests/minute
REST API200 requests/minute
WebSocket1000 messages/minute
ZeroMQUnlimited (local)

Error Handling

Common Errors

CodeErrorDescription
-1Invalid requestMalformed JSON-RPC
-32601Method not foundUnknown method
-5Invalid addressInvalid address format
-6Insufficient fundsNot enough balance
-8Invalid parameterWrong parameter type

Error Response

json
{
    "result": null,
    "error": {
        "code": -6,
        "message": "Insufficient funds"
    },
    "id": "1"
}

Next Steps

Released under the MIT License.