CSPR.Cloud.Net 1.0.6

dotnet add package CSPR.Cloud.Net --version 1.0.6
NuGet\Install-Package CSPR.Cloud.Net -Version 1.0.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSPR.Cloud.Net" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSPR.Cloud.Net --version 1.0.6
#r "nuget: CSPR.Cloud.Net, 1.0.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CSPR.Cloud.Net as a Cake Addin
#addin nuget:?package=CSPR.Cloud.Net&version=1.0.6

// Install CSPR.Cloud.Net as a Cake Tool
#tool nuget:?package=CSPR.Cloud.Net&version=1.0.6

CSPR.Cloud.Net

Release Notes

  • v.1.0.2
    • Fixed an issue where mainnet endpoints were using testnet baseurl.
    • GetAccountInfo endpoint replaced with GetAccountInfoAsync
  • v.1.0.0 Initial Release

Supported Frameworks

The library is targeting both .NET Standard 2.0 and .NET Standard 2.1 for optimal compatibility

To do list

  • Implementation of Streaming API

Get the library

Package Manager

NuGet\Install-Package CSPR.Cloud.Net

.NET CLI

dotnet add package CSPR.Cloud.Net

How to Use

The CasperCloudRestClient class provides an easy way to interact with the CSPR Cloud API for both Mainnet and Testnet environments. Below are the steps to initialize and use the client in your application.

Initialization

To create an instance of the CasperCloudRestClient, you need to provide your API key. Optionally, you can also pass a custom HttpClient and ILoggerFactory for logging purposes.

Step-by-Step Guide
  1. Add Dependencies

    Ensure you have the necessary dependencies in your project. Typically, this includes:

    • HttpClient
    • ILoggerFactory from Microsoft.Extensions.Logging
  2. Create a Configuration Class

    Create an instance of the CasperCloudClientConfig class with your API key.

    public class CasperCloudClientConfig
    {
        public string ApiKey { get; set; }
    
        public CasperCloudClientConfig(string apiKey)
        {
            if (string.IsNullOrEmpty(apiKey))
                throw new ArgumentException("API key is required.", nameof(apiKey));
    
            ApiKey = apiKey;
        }
    }
    

3. Initialize the Client

Initialize the CasperCloudRestClient with your configuration, and optionally pass in a custom HttpClient and ILoggerFactory.

using System.Net.Http;
using Microsoft.Extensions.Logging;

// Configuration with API key
var config = new CasperCloudClientConfig("your-api-key");

// Optional: Custom HttpClient
HttpClient customHttpClient = new HttpClient();

// Optional: LoggerFactory for logging
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

// Create the CasperCloudRestClient
var restClient = new CasperCloudRestClient(config, customHttpClient, loggerFactory);

4. Access Endpoints

Use the Mainnet and Testnet properties to access different endpoints. For example:

// Accessing the Account endpoint on Testnet
var accountData = await restClient.Testnet.Account.GetAccountAsync("public-key");

// Accessing the Block endpoint on Mainnet
var blockData = await restClient.Mainnet.Block.GetBlockAsync("block-hash");

Using Parameterized Requests on Endpoints

Most of the endpoints require optional request parameters wrapped in a RequestParameters class, which includes three possible components:

  1. FilterParameters: Used to filter the results.
  2. SortingParameters: Used to sort the results.
  3. OptionalParameters: Used to include additional data in the results.

Example Usage

Parameters and properties differ for each request depending on the endpoint. Here's an example of how to initialize and use parameterized requests for the Validators endpoint:

// Initialize the request parameters
var parameters = new ValidatorsRequestParameters
{
    // Result is filtered for EraId = 14027 and IsActive = true
    FilterParameters = new ValidatorsFilterParameters
    {
        EraId = "14027",
        IsActive = true
    },
    // Result will include AccountInfo, CentralizedAccountInfo and AveragePerformance Entities
    OptionalParameters = new ValidatorsOptionalParameters
    {
        AccountInfo = true,
        CentralizedAccountInfo = true,
        AveragePerformance = true,
    },
    // Result is sorted by Total Stake because it is set to true and the Sort Direction is Descending
    SortingParameters = new ValidatorsSortingParameters
    {
        OrderByTotalStake = true,
        SortType = SortType.Descending
    }
};

// Execute the request
var result = await _restClient.Testnet.Validator.GetValidatorsAsync(parameters);

Samples

Below are some examples of demonstrating how to use the CasperCloudRestClient.

For more detailed examples of all endpoints, please refer to the CSPRCloudNetTests.cs file.

var config = new CasperCloudClientConfig("your-api-key");
_restClient = new CasperCloudRestClient(config);

// Without parameters
var result = await _restClient.Testnet.Account.GetAccountAsync(_testPublicKey);

// With parameters
var parameters = new AccountInfosRequestParameters
{
    FilterParameters = new AccountInfosFilterParameters
    {
        AccountHashes = new List<string>
        {
            "first-account-hash",
            "second-account-hash"
        }
    }
};
var result = await _restClient.Testnet.Account.GetAccountInfosAsync(parameters);

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

MIT License

Buy me a coffee?

BTC: 1NxUuEQcR4Scw8ge3oto6ykLqBpe9LGikS
ETH: 0x9cda155f73220073a9f024daaa72eb06b5c06c86
CSPR Public Key: 01a0cbbd2f6402c98c745b6d318d15c0b68feef6a17af48ae35e683f05a4e6cbcc

Support my validator on the Casper Network by Delegating

https://cspr.live/delegate-stake?validatorPublicKey=011143c66e8e567bc46e7108736d363dfbbeeb8d0dfbd78aa9728646824999a5e5

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 37 7/1/2024
1.0.2 38 7/1/2024
1.0.0 43 6/26/2024

- Fixed mainnet baseUrl