> ## Documentation Index
> Fetch the complete documentation index at: https://docs.blockdb.io/llms.txt
> Use this file to discover all available pages before exploring further.

# .NET SDK

> Official BlockDB SDK for .NET 10+ — install from NuGet, configure with an API key, and call any EVM endpoint with full async and DI support.

The BlockDB .NET SDK targets **.NET 10** and covers all EVM API endpoints. It sends your API key on every request, and supports cursor-based pagination, retries, and client-side rate limiting.

## Where it's available

* **NuGet:** [BlockDb.Api.Sdk](https://www.nuget.org/packages/BlockDb.Api.Sdk)
* **Source (open source):** [github.com/blockdb-io/blockdb-dotnet-api-sdk](https://github.com/blockdb-io/blockdb-dotnet-api-sdk)

## Installation

```bash theme={null}
dotnet add package BlockDb.Api.Sdk
```

## Quick examples

<CodeGroup>
  ```csharp With DI (ASP.NET Core / Generic Host) theme={null}
  // Program.cs
  using BlockDb.Api.Sdk;

  builder.Services.AddBlockDbClient(options =>
  {
      options.ApiKey = Environment.GetEnvironmentVariable("BLOCKDB_API_KEY")!;
  });

  // Inject and use anywhere
  public class MyService
  {
      private readonly BlockDbClient _blockDb;
      public MyService(BlockDbClient blockDb) => _blockDb = blockDb;

      public async Task<IReadOnlyList<Block>> GetRecentBlocksAsync(CancellationToken ct)
      {
          var response = await _blockDb.Primitives.GetBlocksAsync(new GetBlocksRequest
          {
              ChainId   = 1,
              FromBlock = 21_000_000,
              ToBlock   = 21_001_000,
              Limit     = 100
          }, ct);

          return response.Data;
      }
  }
  ```

  ```csharp Without DI (console / scripts) theme={null}
  using BlockDb.Api.Sdk;

  var client = BlockDbClientFactory.Create(new BlockDbClientOptions
  {
      ApiKey = Environment.GetEnvironmentVariable("BLOCKDB_API_KEY")!,
  });

  var blocks = await client.Primitives.GetBlocksAsync(new GetBlocksRequest
  {
      ChainId   = 1,
      FromBlock = 21_000_000,
      ToBlock   = 21_001_000,
  });

  Console.WriteLine($"Fetched {blocks.Count} blocks.");
  ```
</CodeGroup>

```csharp theme={null}
// 1-hour OHLCV candles for WETH/USDC
var candles = await client.Prices.Crypto.GetOhlcAsync(new GetPricesOhlcRequest
{
    ChainId           = 1,
    BaseTokenAddress  = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH
    QuoteTokenAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC
    FromBlock         = 21_000_000,
    ToBlock           = 21_010_000,
    AggregationInterval = "1h",
});

foreach (var candle in candles.Data)
    Console.WriteLine($"{candle.OpenTimestamp}  O:{candle.Open}  H:{candle.High}  L:{candle.Low}  C:{candle.Close}");
```

## Pagination

Every endpoint returns `PagedResponse<T>` with a `Cursor` property. Pass the cursor back to retrieve the next page.

<CodeGroup>
  ```csharp Manual paging theme={null}
  string? cursor = null;
  do
  {
      var page = await client.Primitives.GetTransactionsAsync(new GetTransactionsRequest
      {
          ChainId   = 1,
          FromBlock = 20_000_000,
          ToBlock   = 20_100_000,
          Limit     = 1000,
          Cursor    = cursor,
      });

      ProcessBatch(page.Data);
      cursor = page.Cursor;
  }
  while (cursor is not null);
  ```

  ```csharp Automatic paging (PaginationExtensions) theme={null}
  using BlockDb.Api.Sdk.Models.Common;

  await foreach (var tx in PaginationExtensions.GetAllItemsAsync(
      new GetTransactionsRequest { ChainId = 1, FromBlock = 20_000_000, ToBlock = 20_100_000 },
      (req, ct) => client.Primitives.GetTransactionsAsync(req, ct)))
  {
      Console.WriteLine(tx.TxHash);
  }
  ```
</CodeGroup>

## Configuration reference

```csharp theme={null}
new BlockDbClientOptions
{
    // Required — from https://dashboard.blockdb.io
    ApiKey = Environment.GetEnvironmentVariable("BLOCKDB_API_KEY")!,

    // Optional overrides
    ApiBaseUrl           = "https://api.blockdb.io",   // default
    HttpTimeout          = TimeSpan.FromSeconds(30), // default
    EnableRetry          = true,
    MaxRetries           = 3,
    RetryBaseDelay       = TimeSpan.FromMilliseconds(500),
    EnableRateLimiting   = true,
    MaxRequestsPerSecond = 100,
}
```

See [Authorization](/api-reference/overview/authorization) for creating and rotating API keys.
