![]() |
VOOZH | about |
dotnet add package Nethereum.BlockchainStore.EFCore --version 6.1.0
NuGet\Install-Package Nethereum.BlockchainStore.EFCore -Version 6.1.0
<PackageReference Include="Nethereum.BlockchainStore.EFCore" Version="6.1.0" />
<PackageVersion Include="Nethereum.BlockchainStore.EFCore" Version="6.1.0" />Directory.Packages.props
<PackageReference Include="Nethereum.BlockchainStore.EFCore" />Project file
paket add Nethereum.BlockchainStore.EFCore --version 6.1.0
#r "nuget: Nethereum.BlockchainStore.EFCore, 6.1.0"
#:package Nethereum.BlockchainStore.EFCore@6.1.0
#addin nuget:?package=Nethereum.BlockchainStore.EFCore&version=6.1.0Install as a Cake Addin
#tool nuget:?package=Nethereum.BlockchainStore.EFCore&version=6.1.0Install as a Cake Tool
Entity Framework Core base library for persisting Ethereum blockchain data (blocks, transactions, logs, contracts, internal transactions) to relational databases.
Nethereum.BlockchainStore.EFCore provides the database-agnostic EF Core layer that sits between the Nethereum.BlockchainProcessing entity models and a specific database provider (PostgreSQL, SQL Server, SQLite, etc.). It defines the DbContext, entity type configurations, and repository implementations that read and write blockchain data using EF Core.
This package is not used directly by most applications. Instead, use a database-specific package such as Nethereum.BlockchainStore.Postgres which inherits from this base and configures the provider.
BlockchainDbContextBase abstract DbContext with DbSets for all blockchain entitiesIBlockRepository, ITransactionRepository, ITransactionLogRepository, IContractRepository, IAddressTransactionRepository, IInternalTransactionRepositoryBlockchainStoreRepositoryFactory implementing IBlockchainStoreRepositoryFactory for the block storage processor pipelineIBlockchainDbContextFactory abstraction allowing short-lived context creation per operationEfCoreReorgHandler (marks blocks, transactions, and logs as non-canonical)AddBlockchainRepositories() extension methoddotnet add package Nethereum.BlockchainStore.EFCore
Targets net8.0 and net10.0. Uses EF Core 8.x on net8.0 and EF Core 10.x on net10.0.
UpsertBlockAsync(RPC.Eth.DTOs.Block))Abstract DbContext subclass that defines all DbSet properties and applies entity configurations via OnModelCreating. Database-specific packages inherit from this and set the provider and ColumnTypeForUnlimitedText (e.g. "text" for Postgres, "nvarchar(max)" for SQL Server).
public class PostgresBlockchainDbContext : BlockchainDbContextBase
{
public PostgresBlockchainDbContext(string connectionString)
{
ColumnTypeForUnlimitedText = "text";
_connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(_connectionString);
}
}
DbSets provided: Blocks, Transactions, TransactionLogs, Contracts, AddressTransactions, InternalTransactions, TransactionVmStacks, AccountStates, ChainStates, BlockProgress, InternalTransactionBlockProgress.
Repository implementations create a new DbContext per operation to avoid long-lived context issues in background processing:
public interface IBlockchainDbContextFactory
{
BlockchainDbContextBase CreateContext();
}
Each repository method calls _contextFactory.CreateContext() in a using block, performs the query or upsert, and disposes the context.
Entity type configurations define column constraints using extension methods:
IsHash() - HasMaxLength(67) for 32-byte hex hashes (66 chars + "0x")IsAddress() - HasMaxLength(43) for 20-byte hex addresses (42 chars + "0x")IsBigInteger() - HasMaxLength(100) for string-encoded large numbers (gas values, balances)IsUnlimitedText(columnType) - HasColumnType("text") or "nvarchar(max)" for input data, error messages, logs bloomNumeric fields that were migrated to long (BlockNumber, Timestamp, TransactionIndex, LogIndex, Nonce, TransactionType) no longer use IsBigInteger().
Most applications use this package indirectly through Nethereum.BlockchainStore.Postgres:
using Nethereum.BlockchainStore.Postgres;
builder.Services.AddPostgresBlockchainStorage(connectionString);
This registers IBlockchainDbContextFactory and all repository implementations via AddBlockchainRepositories().
using Nethereum.BlockchainStore.EFCore;
services.AddSingleton<IBlockchainDbContextFactory>(
new MyDbContextFactory(connectionString));
services.AddBlockchainRepositories();
AddBlockchainRepositories() registers:
IBlockchainStoreRepositoryFactory as BlockchainStoreRepositoryFactoryIBlockProgressRepositoryFactory as BlockchainStoreRepositoryFactoryIChainStateRepositoryFactory as BlockchainStoreRepositoryFactoryIBlockRepository, ITransactionRepository, ITransactionLogRepository, IContractRepository, IAddressTransactionRepository, IBlockProgressRepository, IChainStateRepositoryvar dbContextFactory = new PostgresBlockchainDbContextFactory(connectionString);
var repoFactory = new BlockchainStoreRepositoryFactory(dbContextFactory);
var steps = new BlockStorageProcessingSteps(repoFactory);
var orchestrator = new BlockCrawlOrchestrator(web3.Eth, steps);
var progressRepo = repoFactory.CreateBlockProgressRepository();
var processor = new BlockchainProcessor(orchestrator, progressRepo, lastConfirmedBlockService);
await processor.ExecuteAsync(cancellationToken);
To add support for a new database, inherit from BlockchainDbContextBase:
public class SqliteBlockchainDbContext : BlockchainDbContextBase
{
private readonly string _connectionString;
public SqliteBlockchainDbContext(string connectionString)
{
ColumnTypeForUnlimitedText = "TEXT";
_connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(_connectionString);
}
}
Then implement IBlockchainDbContextFactory:
public class SqliteBlockchainDbContextFactory : IBlockchainDbContextFactory
{
private readonly string _connectionString;
public SqliteBlockchainDbContextFactory(string connectionString)
{
_connectionString = connectionString;
}
public BlockchainDbContextBase CreateContext()
{
return new SqliteBlockchainDbContext(_connectionString);
}
}
Abstract DbContext with blockchain entity DbSets.
Key DbSets:
DbSet<Block> BlocksDbSet<Transaction> TransactionsDbSet<TransactionLog> TransactionLogsDbSet<Contract> ContractsDbSet<InternalTransaction> InternalTransactionsDbSet<BlockProgress> BlockProgressDbSet<ChainState> ChainStatesImplements IBlockchainStoreRepositoryFactory, IBlockProgressRepositoryFactory, IChainStateRepositoryFactory.
Key methods:
CreateBlockRepository() : IBlockRepositoryCreateTransactionRepository() : ITransactionRepositoryCreateTransactionLogRepository() : ITransactionLogRepositoryCreateContractRepository() : IContractRepositoryCreateInternalTransactionRepository() : IInternalTransactionRepositoryCreateBlockProgressRepository() : IBlockProgressRepositoryCreateChainStateRepository() : IChainStateRepositoryCreateReorgHandler() : IReorgHandlerFindByBlockNumberAsync(HexBigInteger blockNumber) : Task<IBlockView>GetMaxBlockNumberAsync() : Task<BigInteger?>UpsertBlockAsync(Block source) : TaskMarkNonCanonicalAsync(BigInteger blockNumber) : Task| Builder | Table | Key Indexes |
|---|---|---|
BlockEntityBuilder |
Blocks | (BlockNumber, Hash) unique; BlockNumber; Hash; ParentHash; (IsCanonical, BlockNumber) |
TransactionEntityBuilder |
Transactions | (BlockNumber, Hash) unique; Hash; AddressFrom; AddressTo; NewContractAddress; (IsCanonical, BlockNumber) |
TransactionLogEntityBuilder |
TransactionLogs | (TransactionHash, LogIndex) unique; BlockNumber; Address; EventHash; (IsCanonical, BlockNumber) |
InternalTransactionEntityBuilder |
InternalTransactions | (TransactionHash, Index) unique; BlockNumber |
ContractEntityBuilder |
Contracts | Address unique |
BlockchainDbContextBaseBlockchainStoreRepositoryFactory to run the processing pipelineIBlockchainDbContextFactory to display indexed dataBlock, Transaction, TransactionLog, etc.) and repository interfaces| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on Nethereum.BlockchainStore.EFCore:
| Package | Downloads |
|---|---|
|
Nethereum.BlockchainStore.EFCore.SqlServer
Store Ethereum blockchain data in Sql Server using Entity Framework core. |
|
|
Nethereum.BlockchainStore.EFCore.Sqlite
Store Ethereum blockchain data in Sqlite using Entity Framework core. |
|
|
Nethereum.BlockchainStorage.Processors
Database-agnostic background hosted services for indexing Ethereum blockchain data with retry, reorg handling, and internal transaction tracing. |
|
|
Nethereum.BlockchainStore.Postgres
Store Ethereum blockchain data in PostgreSQL using Entity Framework Core. |
|
|
Nethereum.BlockchainStore.Sqlite
Store Ethereum blockchain data in SQLite using Entity Framework Core. |
This package is not used by any popular GitHub repositories.