DemoApp is a sample application that demonstrates how to use the Nimiq.RPC SDK to interact with a Nimiq node.
The application reads configuration settings from an appsettings.json
file and makes an RPC call to get the current epoch number.
- .NET 8.0 SDK or later
- Visual Studio 2022 or any other C# IDE
- Internet connection to access the Nimiq node
The application uses an appsettings.json
file to store the RPC settings. Create an appsettings.json
file in the root of your project directory with the following content:
{ "RPCSettings": { "RpcUrl": "http://localhost:8648", "Username": "super", "Password": "secret" } }
Replace the values with your actual RPC URL, username, and password.
- Clone the repository or download the source code.
- Open the project in Visual Studio 2022 or your preferred C# IDE.
- Ensure that the
appsettings.json
file is in the root of your project directory and contains the correct RPC settings. - Build the project to restore the necessary NuGet packages.
- Run the application.
The Program.cs
file contains the main logic of the application. It reads the RPC settings from the appsettings.json
file, creates an instance of NimiqHttpClient
, and makes an RPC call to get the current epoch number.
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.Json
System.Text.Json
- HTTP Client for Nimiq RPC: Implement the HTTP client for basic RPC calls.
- WebSocket Client for Nimiq RPC: Implement WebSocket client for listening to blockchain events (e.g., new blocks, transactions).
- Authentication Handling: Implement username/password authentication via Basic Auth for both HTTP and WebSocket clients.
- Individual RPC Method Calls: Add support for additional Nimiq RPC methods like
getBlockByNumber
,getTransactionCount
,getBlockCount
, etc. - Custom RPC Methods: Add flexibility to call custom methods as per the Nimiq node's configuration.
- Individual RPC Method Calls: Implement functionality to listen for new blocks, transactions, or other events via WebSocket connection.
- Reconnect Logic: Implement automatic reconnect functionality for WebSocket in case of disconnections.
- Transaction Model: Define models for transactions that include relevant properties (e.g., hash, block, sender, recipient, value).
- Block Model: Create models for blocks that include block hash, number, timestamp, and other block-level data.
- Response Models: Define common response models for RPC responses, including error handling.
- JSON Response Handling: Implement methods to handle JSON serialization and deserialization for HTTP and WebSocket responses.
- Error Models: Define a model for errors in both HTTP and WebSocket communication.
- Centralized Logging: Add logging capabilities for RPC call errors, WebSocket disconnections, and response parsing.
- Comprehensive README: Update the README file with detailed instructions, examples, and use cases for both HTTP and WebSocket clients.
- Inline Code Documentation: Add XML comments and explanations to the code for better understanding and usage.
- Unit Testing: Write unit tests for HTTP and WebSocket clients to ensure correctness of individual methods.
- Integration Testing: Implement integration tests to simulate real RPC and WebSocket interactions with a Nimiq node.
This project is licensed under the MIT License. See the LICENSE file for more details.