NetLedger.Sdk 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package NetLedger.Sdk --version 2.0.2
                    
NuGet\Install-Package NetLedger.Sdk -Version 2.0.2
                    
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="NetLedger.Sdk" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NetLedger.Sdk" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="NetLedger.Sdk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NetLedger.Sdk --version 2.0.2
                    
#r "nuget: NetLedger.Sdk, 2.0.2"
                    
#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.
#:package NetLedger.Sdk@2.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NetLedger.Sdk&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=NetLedger.Sdk&version=2.0.2
                    
Install as a Cake Tool

NetLedger SDK for .NET

A .NET SDK for interacting with the NetLedger Server REST API.

Installation

dotnet add package NetLedger.Sdk

Or add a project reference:

dotnet add reference path/to/NetLedger.Sdk.csproj

Quick Start

using NetLedger.Sdk;

// Create a client
using var client = new NetLedgerClient("http://localhost:8080", "your-api-key");

// Check server health
bool isHealthy = await client.Service.HealthCheckAsync();

// Create an account
Account account = await client.Account.CreateAsync("My Account", "Optional notes");

// Add credits and debits
Entry credit = await client.Entry.AddCreditAsync(account.GUID, 100.00m, "Initial deposit");
Entry debit = await client.Entry.AddDebitAsync(account.GUID, 25.50m, "Purchase");

// Get balance
Balance balance = await client.Balance.GetAsync(account.GUID);
Console.WriteLine($"Committed: {balance.CommittedBalance}, Pending: {balance.PendingBalance}");

// Commit pending entries
CommitResult result = await client.Balance.CommitAsync(account.GUID);

Features

Service Operations

// Health check
bool healthy = await client.Service.HealthCheckAsync();

// Get service info
ServiceInfo info = await client.Service.GetInfoAsync();

Account Management

// Create account
Account account = await client.Account.CreateAsync("Account Name", "Notes");

// Get account by GUID
Account account = await client.Account.GetAsync(accountGuid);

// Get account by name
Account account = await client.Account.GetByNameAsync("Account Name");

// Check if account exists
bool exists = await client.Account.ExistsAsync(accountGuid);

// Delete account
await client.Account.DeleteAsync(accountGuid);

// Enumerate accounts with pagination
var result = await client.Account.EnumerateAsync(new AccountEnumerationQuery
{
    MaxResults = 50,
    Skip = 0,
    SearchTerm = "search"
});

Entry Operations

// Add single credit
Entry credit = await client.Entry.AddCreditAsync(accountGuid, 100.00m, "Description");

// Add multiple credits
var credits = await client.Entry.AddCreditsAsync(accountGuid, new List<EntryInput>
{
    new EntryInput(50.00m, "First credit"),
    new EntryInput(25.00m, "Second credit")
});

// Add single debit
Entry debit = await client.Entry.AddDebitAsync(accountGuid, 30.00m, "Description");

// Add multiple debits
var debits = await client.Entry.AddDebitsAsync(accountGuid, new List<EntryInput>
{
    new EntryInput(10.00m, "First debit"),
    new EntryInput(15.00m, "Second debit")
});

// Get all entries
List<Entry> entries = await client.Entry.GetAllAsync(accountGuid);

// Enumerate with filters
var result = await client.Entry.EnumerateAsync(accountGuid, new EntryEnumerationQuery
{
    MaxResults = 100,
    CreatedAfterUtc = DateTime.UtcNow.AddDays(-30),
    AmountMin = 10.00m,
    Ordering = EnumerationOrder.AmountDescending
});

// Get pending entries
List<Entry> pending = await client.Entry.GetPendingAsync(accountGuid);
List<Entry> pendingCredits = await client.Entry.GetPendingCreditsAsync(accountGuid);
List<Entry> pendingDebits = await client.Entry.GetPendingDebitsAsync(accountGuid);

// Cancel a pending entry
await client.Entry.CancelAsync(accountGuid, entryGuid);

Balance Operations

// Get current balance
Balance balance = await client.Balance.GetAsync(accountGuid);

// Get historical balance
Balance historical = await client.Balance.GetAsOfAsync(accountGuid, DateTime.UtcNow.AddDays(-7));

// Get all account balances
List<Balance> balances = await client.Balance.GetAllAsync();

// Commit all pending entries
CommitResult result = await client.Balance.CommitAsync(accountGuid);

// Commit specific entries
CommitResult result = await client.Balance.CommitAsync(accountGuid, new List<Guid> { entry1Guid, entry2Guid });

// Verify balance chain integrity
bool isValid = await client.Balance.VerifyAsync(accountGuid);

API Key Management

// Create API key
ApiKeyInfo apiKey = await client.ApiKey.CreateAsync("Key Name", isAdmin: false);
Console.WriteLine($"Key: {apiKey.ApiKey}"); // Only available on creation

// Enumerate API keys
var result = await client.ApiKey.EnumerateAsync(new ApiKeyEnumerationQuery
{
    MaxResults = 50,
    Skip = 0
});

// Revoke API key
await client.ApiKey.RevokeAsync(apiKeyGuid);

Error Handling

The SDK throws specific exceptions for different error scenarios:

try
{
    var account = await client.Account.GetAsync(accountGuid);
}
catch (NetLedgerConnectionException ex)
{
    // Unable to connect to the server
    Console.WriteLine($"Connection error: {ex.Message}");
}
catch (NetLedgerApiException ex)
{
    // Server returned an error
    Console.WriteLine($"API error {ex.StatusCode}: {ex.Message}");
    if (ex.Details != null)
        Console.WriteLine($"Details: {ex.Details}");
}
catch (NetLedgerValidationException ex)
{
    // Invalid input parameters
    Console.WriteLine($"Validation error for {ex.ParameterName}: {ex.Message}");
}

Configuration

var client = new NetLedgerClient("http://localhost:8080", "your-api-key");

// Set custom timeout (default: 30 seconds)
client.TimeoutMs = 60000; // 60 seconds

Thread Safety

The NetLedgerClient is thread-safe and can be reused across multiple operations. It is recommended to create a single instance and share it across your application.

Disposal

The client implements IDisposable. Always dispose of it when done:

using var client = new NetLedgerClient("http://localhost:8080", "your-api-key");
// Use client...
// Automatically disposed at end of scope

Or manually:

var client = new NetLedgerClient("http://localhost:8080", "your-api-key");
try
{
    // Use client...
}
finally
{
    client.Dispose();
}

License

MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

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
4.0.0 200 7/31/2026
2.0.2 388 12/28/2025
2.0.1 215 12/25/2025

Initial release