A high-performance JSON-RPC server implementation for Shardeum-related EVM blockchain interactions, built with Rust and love.
- Fast & Reliable: Built with Rust for optimal performance and memory safety
- JSON-RPC 2.0: Full compliance with JSON-RPC 2.0 specification
- Configurable: TOML-based configuration with sensible defaults
- Asynchronous: Non-blocking I/O using Tokio runtime
- Extensible: Modular architecture for easy method additions
- CI/CD Ready: GitHub Actions workflow for automated testing
- Rust 1.70+ (2021 edition)
- Cargo package manager
-
Clone the repository
git clone <repository-url> cd rust_rpc
-
Build the project
cargo build --release
-
Run the server
cargo run
The server uses a TOML configuration file located at src/config.toml
. Customize these settings:
# Server settings
host = "localhost"
port = 8080
request_timeout = 30 # in seconds
verbose = true
# List of node URLs
node_urls = [
"http://localhost:3000"
]
Option | Type | Default | Description |
---|---|---|---|
host |
String | "localhost" |
Server bind address |
port |
Integer | 8080 |
Server port |
request_timeout |
Integer | 30 |
Request timeout in seconds |
verbose |
Boolean | false |
Enable verbose logging |
node_urls |
Array | ["http://localhost:3000"] |
List of Network node URLs |
The server accepts JSON-RPC 2.0 requests via HTTP POST to the root endpoint /
.
{
"jsonrpc": "2.0",
"method": "method_name",
"params": {},
"id": 1
}
{
"jsonrpc": "2.0",
"result": "response_data",
"error": null,
"id": 1
}
dummy
- Test method that returns the method name
curl -X POST http://localhost:8080 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "dummy",
"params": {},
"id": 1
}'
src/
├── main.rs # Application entry point and server setup
├── api.rs # JSON-RPC request/response structures
├── config.rs # Configuration management
├── methods.rs # RPC method implementations
├── shardeum.rs # Shardeum-specific functionality
├── middleware.rs # HTTP middleware (future use)
├── utils.rs # Utility functions (future use)
└── config.toml # Configuration file
Run the test suite:
cargo test --verbose
Check code formatting:
cargo fmt --check
-
Implement the method in
src/methods.rs
:pub fn your_method(payload: RpcRequest) -> RpcResponse { // Your implementation here }
-
Register the method in
src/main.rs
:match method.as_str() { "dummy" => methods::lib_dummy(payload), "your_method" => methods::your_method(payload), // ... }
This project follows standard Rust formatting. Run cargo fmt
before committing.
- axum (0.8.4) - Web framework
- tokio (1.46.1) - Async runtime
- reqwest (0.12.22) - HTTP client
- serde (1.0.219) - Serialization framework
- tracing (0.1.41) - Logging framework
- toml (0.8) - Configuration parsing
The project includes a GitHub Actions workflow that:
- Checks code formatting
- Builds the project
- Runs all tests
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues or have questions:
- Check the Issues section
- Create a new issue with detailed information
- Include relevant logs and configuration details
Built with ❤️ and Rust