ShiwakeDocs

Installation

Install the NuGet package and register services.

Requirements

Install the package

dotnet add package LedgerCore.Sdk

Or in a .csproj:

<PackageReference Include="LedgerCore.Sdk" Version="1.0.0" />

The package brings in Microsoft.Extensions.DependencyInjection.Abstractions, Microsoft.Extensions.Http, and Microsoft.Extensions.Options as its only runtime dependencies.

Register the core client

In Program.cs:

using LedgerCore.Sdk;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLedgerCoreSdk(options =>
{
    options.BaseUrl = "https://api.shiwake.example.com";
    options.ApiKey  = builder.Configuration["LedgerCore:ApiKey"]!;
});

This registers ILedgerCoreClient as a transient service backed by a managed HttpClient via IHttpClientFactory. Inject it anywhere:

public class DepositHandler(ILedgerCoreClient ledger)
{
    public async Task HandleAsync(/* ... */) { /* ... */ }
}

Register the banking clients

Two different banking clients ship with the SDK: register whichever you need (or both).

Banking API client (full)

For production banking workloads: wallets, fee schedules, hold/capture withdrawals, limits, suspense, statements, audit. See IBankingApiClient.

builder.Services.AddLedgerCoreSdk(options => { /* ... */ });
builder.Services.AddLedgerCoreBankingApi();

IBankingApiClient is then injectable:

public class WalletController(IBankingApiClient banking) : ControllerBase
{
    // ...
}

Banking client (simple)

A minimal wrapper that posts journal entries directly, no wallets, no fees. Right for very small products or quick prototypes. See IBankingClient.

builder.Services.AddLedgerCoreSdk(options => { /* ... */ });
builder.Services.AddLedgerCoreBanking(); // uses PlatformFloatAccountCode = "PLATFORM-FLOAT"

Or override the defaults:

builder.Services.AddLedgerCoreBanking(options =>
{
    options.PlatformFloatAccountCode = "MAIN-FLOAT";
    options.ClientAccountCodePrefix  = "WALLET-";
});

Binding from appsettings.json

There is an overload that binds directly from IConfiguration:

{
  "LedgerCore": {
    "BaseUrl": "https://api.shiwake.example.com",
    "ApiKey": "sk_live_...",
    "ApiVersion": "1",
    "TimeoutSeconds": 30
  }
}
builder.Services.AddLedgerCoreSdk(builder.Configuration);
builder.Services.AddLedgerCoreBankingApi();

The default section name is "LedgerCore". Pass a second argument to override it.

Do not commit API keys to appsettings.json. Use user secrets in development and environment variables / a key vault in production.

Verifying the install

A quick smoke test. List accounts in your tenant:

var ledger = app.Services.GetRequiredService<ILedgerCoreClient>();
var page = await ledger.ListAccountsAsync(size: 5);
Console.WriteLine($"Got {page.Accounts.Count} accounts");

If that runs without throwing, you're wired up correctly. If you see a LedgerCoreException with status 401, the API key is wrong. 403 means the tenant is disabled. See Error handling.

Edit on GitHub

Last updated on

On this page