BitcoinBlockchainParser 1.0.9

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

BitcoinBlockchainParser

NuGet License: MIT

A lightweight .NET library for reading raw Bitcoin block files produced by Bitcoin Core.

Features

  • Reads Bitcoin Core blk*.dat block files
  • Enumerates blocks in file order or in blockchain height order
  • Resumes parsing from a block file and byte position
  • Detects outputs types
  • Detects addresses in outputs
  • Interprets scripts
  • Supports SegWit and Taproot
  • Supports mainnet, testnet, and regtest
  • Supports file XOR-deobfuscation (Bitcoin Core 28.0 or newer)

Requirements

  • A local Bitcoin Core blocks directory containing blk*.dat files
  • Sufficient disk access for the block files

Installation

dotnet add package BitcoinBlockchainParser

Quick start

Pass the Bitcoin Core blocks directory to Blockchain. Mainnet is selected by default.

using BitcoinBlockchainParser;

var blockchain = new Blockchain(@"C:\Bitcoin\blocks");

foreach (var block in blockchain.EnumerateBlocks().Take(5))
{
    Console.WriteLine($"Block: {block.Id}");
    Console.WriteLine($"Time:  {block.Time:o}");

    foreach (var tx in block.Transactions.Take(3))
    {
        Console.WriteLine(
            $"  TX: {tx.TXID}; inputs: {tx.Inputs.Length}; outputs: {tx.Outputs.Length}");
    }
}

Parsing modes

Unordered blocks

EnumerateBlocks() yields blocks as they appear in blk*.dat files. This is the fastest option when blockchain order is not required.

foreach (var block in blockchain.EnumerateBlocks())
{
    // block: BlockFiled
    // block.FilePosition contains the source file number and byte position
}

You can start at a specific file and byte position:

foreach (var block in blockchain.EnumerateBlocks(
             startFile: 100,
             position: 1024))
{
    Console.WriteLine(block.Id);
}

For a single block file:

foreach (var block in blockchain.EnumerateFileBlocks(file: 100))
{
    Console.WriteLine(block.Id);
}

Ordered blocks

EnumerateBlocksOrdered() yields blocks in chain order and includes the calculated block height.

foreach (var block in blockchain.EnumerateBlocksOrdered().Skip(50).Take(20))
{
    Console.WriteLine($"#{block.Height} {block.Id}");
}

Ordered parsing needs to connect block hashes and may buffer out-of-order blocks while traversing the available files.

The network affects address encoding and block magic validation.

Transactions and addresses

foreach (var block in blockchain.EnumerateBlocks().Take(1))
{
    foreach (var tx in block.Transactions)
    {
        foreach (var output in tx.Outputs)
        {
            Console.WriteLine($"Type:    {output.Type}");
            Console.WriteLine($"Address: {output.Address}");
            Console.WriteLine($"Sats:    {output.Amount}");
            Console.WriteLine($"Script:  {output.ScriptPubKey}");
        }
    }
}

TxOutput.Amount is expressed in satoshis. TxOutput.Address may be null for scripts that do not map to a supported address format, such as OP_RETURN or an unknown script.

Networks

Mainnet is the default. Specify another network explicitly:

var mainnet = new Blockchain(@"C:\Bitcoin\blocks", Network.Mainnet);
var testnet = new Blockchain(@"C:\BitcoinTestnet\blocks", Network.Testnet3);
var regtest = new Blockchain(@"C:\BitcoinRegtest\blocks", Network.Regtest);

Example application

A runnable console example is available at ExampleApp/Program.cs.

Package notes

  • EnumerateBlocks() and EnumerateBlocksOrdered() are lazy; each call starts reading from the source files.
  • Block IDs and transaction IDs are returned as reversed-display hex strings by HashId.Id.
  • Bitcoin Core 28.0+ may store obfuscated block files. The library automatically looks for xor.dat in the supplied blocks directory.
  • Parsing a pruned Bitcoin Core installation provides only blocks that are still present locally.

License

MIT - see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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.  net11.0 is compatible. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.9 107 11/28/2026
1.0.8 949 7/19/2025
1.0.7 234 7/17/2025
1.0.6 204 7/11/2025
1.0.3 253 7/9/2025
1.0.2 257 6/25/2025
1.0.1 254 6/23/2025
1.0.0 261 6/22/2025