Nethereum.BlockchainStore.SqlServer 6.0.4

Prefix Reserved
dotnet add package Nethereum.BlockchainStore.SqlServer --version 6.0.4
                    
NuGet\Install-Package Nethereum.BlockchainStore.SqlServer -Version 6.0.4
                    
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="Nethereum.BlockchainStore.SqlServer" Version="6.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nethereum.BlockchainStore.SqlServer" Version="6.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Nethereum.BlockchainStore.SqlServer" />
                    
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 Nethereum.BlockchainStore.SqlServer --version 6.0.4
                    
#r "nuget: Nethereum.BlockchainStore.SqlServer, 6.0.4"
                    
#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 Nethereum.BlockchainStore.SqlServer@6.0.4
                    
#: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=Nethereum.BlockchainStore.SqlServer&version=6.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Nethereum.BlockchainStore.SqlServer&version=6.0.4
                    
Install as a Cake Tool

Nethereum.BlockchainStore.SqlServer

SQL Server implementation of the Nethereum blockchain storage layer using Entity Framework Core.

Overview

Nethereum.BlockchainStore.SqlServer provides the SQL Server-specific DbContext, context factory, and DI registration for storing indexed Ethereum blockchain data. It inherits from Nethereum.BlockchainStore.EFCore.BlockchainDbContextBase and uses Microsoft.EntityFrameworkCore.SqlServer.

Supports optional schema isolation, allowing multiple blockchain datasets to coexist in the same database using different SQL Server schemas.

Key Features

  • SqlServerBlockchainDbContext configured with UseSqlServer() and optional schema support
  • SqlServerBlockchainDbContextFactory implementing IBlockchainDbContextFactory
  • AddSqlServerBlockchainStorage() DI extension that registers the factory and all EFCore repositories
  • Design-time factory for dotnet ef migrations tooling
  • Schema isolation for multi-chain storage in a single database

Installation

dotnet add package Nethereum.BlockchainStore.SqlServer

Targets net8.0 and net10.0.

Dependencies

  • Nethereum.BlockchainStore.EFCore - Base BlockchainDbContextBase, entity builders, and repository implementations
  • Nethereum.Microsoft.Configuration.Utils - ConfigurationUtils.Build() for appsettings-based connection string resolution
  • Microsoft.EntityFrameworkCore.SqlServer - SQL Server EF Core provider
  • Microsoft.EntityFrameworkCore.Design - Design-time migration support (private asset)

Quick Start

using Nethereum.BlockchainStore.SqlServer;

var builder = WebApplication.CreateBuilder(args);

var connectionString = builder.Configuration.GetConnectionString("SqlServerConnection");

builder.Services.AddSqlServerBlockchainStorage(connectionString);

This registers IBlockchainDbContextFactory and all repository implementations via AddBlockchainRepositories().

Usage Examples

With Schema Isolation

Store data for different chains in the same database using SQL Server schemas:

builder.Services.AddSqlServerBlockchainStorage(connectionString, schema: "mainnet");

Run Migrations

cd src/Nethereum.BlockchainStore.SqlServer

dotnet ef migrations add InitialCreate \
  --context SqlServerBlockchainDbContext

dotnet ef database update \
  --context SqlServerBlockchainDbContext

Direct Context Usage

var factory = new SqlServerBlockchainDbContextFactory(connectionString);
using var context = factory.CreateContext();

var latestBlock = await context.Blocks
    .Where(b => b.IsCanonical)
    .OrderByDescending(b => b.BlockNumber)
    .FirstOrDefaultAsync();

With Block Storage Processor

var factory = new SqlServerBlockchainDbContextFactory(connectionString);
var repoFactory = new BlockchainStoreRepositoryFactory(factory);

var steps = new BlockStorageProcessingSteps(repoFactory);
var orchestrator = new BlockCrawlOrchestrator(web3.Eth, steps);

var processor = new BlockchainProcessor(
    orchestrator,
    repoFactory.CreateBlockProgressRepository(),
    lastConfirmedBlockService);

await processor.ExecuteAsync(cancellationToken);

Connection String Resolution

SqlServerBlockchainDbContext resolves the connection string in this order:

  1. Constructor parameter (explicit string)
  2. ConnectionStrings:SqlServerConnection from appsettings.json
  3. ConnectionStrings:BlockchainDbStorage from appsettings.json

Database Schema

All tables use the same schema as Nethereum.BlockchainStore.EFCore with nvarchar(max) for unlimited text fields. Numeric indexing fields (BlockNumber, Timestamp, TransactionIndex, LogIndex, Nonce, TransactionType) are stored as bigint.

Dependencies

  • Nethereum.BlockchainStore.EFCore - Base DbContext, entity builders, repositories

See Also

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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Nethereum.BlockchainStore.SqlServer:

Package Downloads
Nethereum.BlockchainStorage.Processors.SqlServer

SQL Server-specific DI registration for the Nethereum blockchain indexer hosted services.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.4 45 3/18/2026
6.0.3 32 3/18/2026
6.0.1 44 3/17/2026
6.0.0 46 3/16/2026