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 build only the libbitcoinkernel shared library. Refer to Bitcoin Core's build documentation to for the minimum requirements to compile libbitcoinkernel from source:
(Unix,
macOS,
Windows)
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).
Your Go application will have a runtime dependency on the shared libbitcoinkernel library produced by make build-kernel in /path/to/go-bitcoinkernel/depend/bitcoin/build. Do not delete or move these built library files as your application needs them to run.