.NET bindings for libbitcoinkernel, providing access to Bitcoin Core's consensus and validation logic.
This library uses libbitcoinkernel which is in an experimental state, do not use for production purposes.
| Package | Version | Description |
|---|---|---|
| BitcoinKernel | 0.2.0 | Managed wrappers and native bindings |
dotnet add package BitcoinKernelThe library is organized in two layers:
- BitcoinKernel.Interop - P/Invoke bindings to libbitcoinkernel (bundled, not published separately)
- BitcoinKernel - Managed C# wrappers with automatic memory management
┌─────────────────────────────┐
│ BitcoinKernel │ ← Managed wrappers, IDisposable
│ (Wrapper Layer) │
└─────────────┬───────────────┘
│
┌─────────────▼───────────────┐
│ BitcoinKernel.Interop │ ← P/Invoke bindings (bundled)
│ (Binding Layer) │
└─────────────┬───────────────┘
│
┌─────────────▼───────────────┐
│ libbitcoinkernel │ ← Native C library
│ (Bitcoin Core) │
└─────────────────────────────┘
using BitcoinKernel;
using BitcoinKernel.Chain;
using BitcoinKernel.Interop.Enums;
using var logging = new LoggingConnection((category, message, level) =>
Console.WriteLine($"[{category}] {message}"));
using var chainParams = new ChainParameters(ChainType.MAINNET);
using var contextOptions = new KernelContextOptions().SetChainParams(chainParams);
using var context = new KernelContext(contextOptions);
using var options = new ChainstateManagerOptions(context, dataDir, blocksDir);
using var chainstate = new ChainstateManager(context, chainParams, options);
var chain = chainstate.GetActiveChain();
Console.WriteLine($"Height: {chain.Height}");
Console.WriteLine($"Genesis: {Convert.ToHexString(chain.GetGenesis().GetBlockHash())}");Explore the examples directory for complete working samples:
- BasicUsage - Getting started with chain queries
- BlockProcessing - Block validation and processing
A conformance test handler for the Kernel bindings test framework, see tools/kernel-bindings-test-handler for details.
dotnet run --project tools/kernel-bindings-test-handler- .NET 9.0 SDK or later
git clone https://github.com/janb84/BitcoinKernel.NET.git
cd BitcoinKernel.NET
dotnet builddotnet testThis package includes pre-built libbitcoinkernel binaries for:
- macOS (x64, ARM64)
- others will follow
For other platforms, you'll need to build libbitcoinkernel from the Bitcoin Core repository.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built on libbitcoinkernel from Bitcoin Core
Note: This library provides access to Bitcoin Core's consensus engine. libbitcoinkernel and this package are still experimental and not ready for production use.