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
<PackageReference Include="Nethereum.BlockchainStore.SqlServer" Version="6.0.4" />
<PackageVersion Include="Nethereum.BlockchainStore.SqlServer" Version="6.0.4" />
<PackageReference Include="Nethereum.BlockchainStore.SqlServer" />
paket add Nethereum.BlockchainStore.SqlServer --version 6.0.4
#r "nuget: Nethereum.BlockchainStore.SqlServer, 6.0.4"
#:package Nethereum.BlockchainStore.SqlServer@6.0.4
#addin nuget:?package=Nethereum.BlockchainStore.SqlServer&version=6.0.4
#tool nuget:?package=Nethereum.BlockchainStore.SqlServer&version=6.0.4
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
SqlServerBlockchainDbContextconfigured withUseSqlServer()and optional schema supportSqlServerBlockchainDbContextFactoryimplementingIBlockchainDbContextFactoryAddSqlServerBlockchainStorage()DI extension that registers the factory and all EFCore repositories- Design-time factory for
dotnet ef migrationstooling - 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:
- Constructor parameter (explicit string)
ConnectionStrings:SqlServerConnectionfromappsettings.jsonConnectionStrings:BlockchainDbStoragefromappsettings.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.
Related Packages
Dependencies
- Nethereum.BlockchainStore.EFCore - Base DbContext, entity builders, repositories
See Also
- Nethereum.BlockchainStore.EFCore - Database-agnostic EF Core base
- Nethereum.BlockchainStore.Postgres - PostgreSQL implementation
- Nethereum.BlockchainStore.Sqlite - SQLite implementation
- Nethereum.BlockchainProcessing - Processing framework and entity definitions
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.0)
- Nethereum.BlockchainStore.EFCore (>= 6.0.4)
- Newtonsoft.Json (>= 13.0.3)
-
net8.0
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.10)
- Nethereum.BlockchainStore.EFCore (>= 6.0.4)
- Newtonsoft.Json (>= 11.0.2 && < 14.0.0)
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.