![]() |
VOOZH | about |
dotnet add package Nethereum.BlockchainStore.Postgres --version 6.1.0
NuGet\Install-Package Nethereum.BlockchainStore.Postgres -Version 6.1.0
<PackageReference Include="Nethereum.BlockchainStore.Postgres" Version="6.1.0" />
<PackageVersion Include="Nethereum.BlockchainStore.Postgres" Version="6.1.0" />Directory.Packages.props
<PackageReference Include="Nethereum.BlockchainStore.Postgres" />Project file
paket add Nethereum.BlockchainStore.Postgres --version 6.1.0
#r "nuget: Nethereum.BlockchainStore.Postgres, 6.1.0"
#:package Nethereum.BlockchainStore.Postgres@6.1.0
#addin nuget:?package=Nethereum.BlockchainStore.Postgres&version=6.1.0Install as a Cake Addin
#tool nuget:?package=Nethereum.BlockchainStore.Postgres&version=6.1.0Install as a Cake Tool
PostgreSQL implementation of the Nethereum blockchain storage layer using Entity Framework Core and Npgsql.
Nethereum.BlockchainStore.Postgres provides the PostgreSQL-specific DbContext, context factory, and DI registration for storing indexed Ethereum blockchain data. It inherits from Nethereum.BlockchainStore.EFCore.BlockchainDbContextBase and configures Npgsql with lowercase naming conventions.
This package is used by the blockchain processing pipeline to persist blocks, transactions, logs, contracts, internal transactions, and chain state to PostgreSQL. It is also used by the Explorer to query indexed data.
PostgresBlockchainDbContext configured with UseNpgsql() and UseLowerCaseNamingConvention()PostgresBlockchainDbContextFactory implementing IBlockchainDbContextFactory for short-lived context creationAddPostgresBlockchainStorage() DI extension that registers the factory and all EFCore repositoriesdotnet ef migrations toolingdotnet add package Nethereum.BlockchainStore.Postgres
Targets net8.0 and net10.0. Uses Npgsql.EntityFrameworkCore.PostgreSQL 8.x on net8.0 and 10.x on net10.0.
BlockchainDbContextBase, entity builders, and repository implementationsConfigurationUtils.Build() for appsettings-based connection string resolutionUseLowerCaseNamingConvention() for snake_case table/column namesusing Nethereum.BlockchainStore.Postgres;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("PostgresConnection");
builder.Services.AddPostgresBlockchainStorage(connectionString);
This single call registers:
IBlockchainDbContextFactory as PostgresBlockchainDbContextFactoryAddBlockchainRepositories() (IBlockRepository, ITransactionRepository, ITransactionLogRepository, IContractRepository, etc.)cd src/Nethereum.BlockchainStore.Postgres
dotnet ef migrations add InitialCreate \
--context PostgresBlockchainDbContext
dotnet ef database update \
--context PostgresBlockchainDbContext
The design-time factory (PostgresBlockchainDesignTimeDbContextFactory) reads the connection string from appsettings.json:
{
"ConnectionStrings": {
"PostgresConnection": "Host=localhost;Database=nethereumdb;Username=postgres;Password=postgres"
}
}
var factory = new PostgresBlockchainDbContextFactory(connectionString);
using var context = factory.CreateContext();
await context.Database.MigrateAsync();
var factory = new PostgresBlockchainDbContextFactory(connectionString);
using var context = factory.CreateContext();
var latestBlock = await context.Blocks
.Where(b => b.IsCanonical)
.OrderByDescending(b => b.BlockNumber)
.FirstOrDefaultAsync();
var txCount = await context.Transactions
.Where(t => t.BlockNumber == latestBlock.BlockNumber && t.IsCanonical)
.CountAsync();
var dbContextFactory = new PostgresBlockchainDbContextFactory(connectionString);
var repoFactory = new BlockchainStoreRepositoryFactory(dbContextFactory);
var steps = new BlockStorageProcessingSteps(repoFactory);
var orchestrator = new BlockCrawlOrchestrator(web3.Eth, steps);
orchestrator.ContractCreatedCrawlerStep.RetrieveCode = true;
var processor = new BlockchainProcessor(
orchestrator,
repoFactory.CreateBlockProgressRepository(),
lastConfirmedBlockService);
await processor.ExecuteAsync(cancellationToken);
PostgresBlockchainDbContext resolves the connection string in this order:
ConnectionStrings:PostgresConnection from appsettings.jsonConnectionStrings:BlockchainDbStorage from appsettings.jsonAll table and column names use lowercase convention via EFCore.NamingConventions.
| Table | Entity | Key Columns |
|---|---|---|
blocks |
Block |
blocknumber (bigint), hash, parenthash, miner, timestamp (bigint), gasused, gaslimit, basefeepergas, blobgasused, excessblobgas, parentbeaconblockroot, requestshash |
transactions |
Transaction |
blocknumber (bigint), hash, addressfrom, addressto, transactionindex (bigint), timestamp (bigint), value, gas, gasprice, gasused, transactiontype (bigint), maxfeeperblobgas, blobgasused, blobgasprice |
transactionlogs |
TransactionLog |
transactionhash, logindex (bigint), blocknumber (bigint), address, eventhash, data |
contracts |
Contract |
address, name, abi, code, creator, transactionhash |
internaltransactions |
InternalTransaction |
transactionhash, index, blocknumber (bigint), from, to, value, type |
blockprogress |
BlockProgress |
lastblockprocessed |
chainstates |
ChainState |
lastcanonicalblocknumber (bigint, nullable), finalizedblocknumber (bigint, nullable), chainid |
accountstates |
AccountState |
address, balance, nonce (bigint), lastupdatedblock (bigint) |
Numeric fields (blocknumber, timestamp, transactionindex, logindex, nonce, transactiontype) are stored as bigint (long). Gas and value fields remain as character varying(100) strings to accommodate full uint256 range.
IBlockchainDbContextFactory| 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 1 NuGet packages that depend on Nethereum.BlockchainStore.Postgres:
| Package | Downloads |
|---|---|
|
Nethereum.BlockchainStorage.Processors.Postgres
PostgreSQL-specific DI registration for the Nethereum blockchain indexer hosted services. |
This package is not used by any popular GitHub repositories.