Overview
Viction provides a JSON-RPC API for interacting with the blockchain. The RPC API is compatible with Ethereum’s JSON-RPC specification, making it easy to integrate existing Ethereum tools and libraries.Connection Methods
Viction supports multiple RPC connection methods:HTTP/HTTPS
HTTP is the most common method for RPC calls:--rpc: Enable HTTP-RPC server--rpcaddr: HTTP-RPC server listening interface (default: “localhost”)--rpcport: HTTP-RPC server listening port (default: 8545)--rpcapi: API’s offered over HTTP-RPC interface--rpccorsdomain: Comma separated list of domains to accept cross-origin requests--rpcvhosts: Comma separated list of virtual hostnames to accept requests
WebSocket
WebSocket provides real-time event subscriptions:--ws: Enable WS-RPC server--wsaddr: WS-RPC server listening interface (default: “localhost”)--wsport: WS-RPC server listening port (default: 8546)--wsapi: API’s offered over WS-RPC interface--wsorigins: Origins from which to accept websocket requests
IPC (Inter-Process Communication)
IPC provides the fastest and most secure local connection:API Namespaces
Viction organizes RPC methods into namespaces:eth (Ethereum Compatible)
Core blockchain operations:eth_blockNumber: Get latest block numbereth_getBalance: Get account balanceeth_getBlockByNumber: Get block by numbereth_getBlockByHash: Get block by hasheth_getTransactionByHash: Get transaction detailseth_getTransactionReceipt: Get transaction receipteth_sendRawTransaction: Send signed transactioneth_call: Execute read-only contract calleth_estimateGas: Estimate gas for transactioneth_getLogs: Get event logseth_subscribe: Subscribe to events (WebSocket only)
net
Network information:net_version: Get network IDnet_listening: Check if client is listeningnet_peerCount: Get number of connected peers
web3
Utility methods:web3_clientVersion: Get client versionweb3_sha3: Calculate Keccak-256 hash
personal
Account management (use with caution):personal_newAccount: Create new accountpersonal_unlockAccount: Unlock accountpersonal_sendTransaction: Send transactionpersonal_sign: Sign data
txpool
Transaction pool inspection:txpool_content: Get pending and queued transactionstxpool_inspect: Inspect transaction pooltxpool_status: Get transaction pool status
debug
Advanced debugging (requires--vmodule flag):
debug_traceTransaction: Trace transaction executiondebug_traceBlock: Trace block executiondebug_getBlockRlp: Get RLP-encoded block
Making RPC Calls
Using cURL
Using JavaScript (Node.js)
RPC Server Implementation
Viction’s RPC server is built on a flexible architecture:Server Features
- Concurrent Request Handling: Multiple requests processed simultaneously
- Out-of-Order Responses: Responses can be sent back in any order
- Multiple Codecs: JSON-RPC over HTTP, WebSocket, and IPC
- Service Registration: Dynamic method registration
- Publish/Subscribe: Real-time event subscriptions
Method Requirements
For a method to be exposed via RPC, it must satisfy:- Object must be exported
- Method must be exported
- Method returns 0, 1 (response or error), or 2 (response and error) values
- Method arguments must be exported or builtin types
- Method return values must be exported or builtin types
Example Service
Subscriptions (WebSocket)
WebSocket connections support publish/subscribe for real-time updates:Available Subscriptions
newHeads: New block headerslogs: Event logs matching filter criterianewPendingTransactions: New pending transactionssyncing: Sync status changes
Subscription Example
Rate Limiting and Security
Best Practices
- Never expose personal API publicly:
personalnamespace should only be used locally - Use HTTPS in production: Encrypt RPC traffic
- Implement rate limiting: Use reverse proxy (nginx, HAProxy)
- Restrict API methods: Only enable necessary namespaces
- Configure CORS carefully: Restrict origins in
--rpccorsdomain - Use firewall rules: Limit access to RPC ports
Production Configuration
Batch Requests
Reduce latency by batching multiple RPC calls:Error Handling
Common Error Codes
-32700: Parse error-32600: Invalid request-32601: Method not found-32602: Invalid params-32603: Internal error-32000: Server error (custom)
Example Error Response
Performance Optimization
Connection Management
- Keep-Alive: HTTP connections use TCP keep-alive (30s interval)
- Timeout Settings: Default dial timeout is 10s, write timeout is 10s
- Subscription Buffer: Max buffer size is 8000 items
Payload Limits
- Max Request Size: 128KB (131,072 bytes)
- Max WebSocket Payload: Configurable per connection
Public RPC Endpoints
Viction provides public RPC endpoints: Mainnet:- HTTP:
https://rpc.viction.xyz - WebSocket:
wss://ws.viction.xyz
- HTTP:
https://rpc-testnet.viction.xyz - WebSocket:
wss://ws-testnet.viction.xyz
Public endpoints have rate limits. For production applications, run your own node.