A Go wrapper for Bitcoin Core's libbitcoinkernel library.
This library is experimental and not production-ready. The underlying C API is subject to change, which may cause breaking changes in this wrapper. The wrapper itself may also change based on user feedback, which is welcome and appreciated. Feel free to open issues to help make this wrapper more useful for everyone.
This repository consists of:
- Bitcoin Core Source: Git subtree containing Bitcoin Core source code with
libbitcoinkernelC API - Kernel Package: Safe, idiomatic Go interfaces with integrated CGO bindings that manage memory and provide error handling
- Utils Package: Helper functions and utilities built on the kernel package wrappers for common operations
Since this library includes native C++ dependencies that must be compiled from source, it cannot be installed directly
via go get (at least for now). Follow these steps:
git clone https://github.com/stringintech/go-bitcoinkernel.git
cd go-bitcoinkernelmake build-kernelThis command will configure Bitcoin Core's CMake build system and statically compile the libbitcoinkernel library. Building requires CMake, a C++ compiler, Boost library, and Make. For platform-specific setup instructions, consult Bitcoin Core's build documentation:
(Unix,
macOS,
Windows)
Addtional note for Windows: MinGW toolchain is required. CGo uses GCC on Windows, so static linking requires the library to be compiled with GCC/MinGW rather than MSVC for ABI compatibility.
make testThis ensures that both the native library and Go bindings are working correctly.
The tests also include examples demonstrating how to use different components. For example, see:
In your Go project directory, add a replace directive to point to your local copy:
# Initialize your Go module (if not already done)
go mod init your-project-name
# Add replace directive to use local go-bitcoinkernel
go mod edit -replace github.com/stringintech/go-bitcoinkernel=/path/to/go-bitcoinkernel
# Add the dependency
go get github.com/stringintech/go-bitcoinkernel/kernelYour go.mod file should look like this:
module your-project-name
go 1.23.3
require github.com/stringintech/go-bitcoinkernel/kernel v0.0.0-00010101000000-000000000000
replace github.com/stringintech/go-bitcoinkernel => /path/to/go-bitcoinkernelThe library handles memory management automatically through Go's finalizers (see common.go), but it's highly recommended to explicitly
call Destroy() methods when you're done with owned objects to free resources immediately.
The library uses structured error types for better error handling (see errors.go).