NBitcoin is the most complete Bitcoin library for the .NET platform. It implements all most relevant Bitcoin Improvement Proposals (BIPs). It also provides low level access to Bitcoin primitives so you can easily build your application on top of it.
It works on Windows, Mac and Linux with Xamarin, Unity, .NET Core or CLR.
You can browse the API easily through the API reference.
You can use it in .NET Core:
dotnet add package NBitcoin
If using legacy .NET Framework in Visual Studio
Install-Package NBitcoin
You can also just use the Manage NuGet
Package
window on your project in Visual Studio.
The packages support with full features: Windows Desktop applications, Mono Desktop applications and platforms supported by .NET Standard 1.3 (.NET Core, Xamarin IOS, Xamarin Android, UWP and more) also with limited features: platforms supported by .NET Standard 1.1 (Windows Phone, Windows 8.0 apps).
First, you need to understand Bitcoin, for this read:
Once you get familiar with Bitcoin terminology with this book, follow up by reading:
This will teach you how to use NBitcoin in a practical way.
Install-Package NBitcoin.Altcoins
Find more information here.
Find more information here.
You should use at least Unity 2018.2
using Script Runtime Version
.NET 4.x Equivalent
and Api Compatibility Level
.NET Standard 2.0
. You can see more on this post.
Then you need to compile NBitcoin:
git clone https://github.com/MetacoSA/NBitcoin/
cd NBitcoin/NBitcoin
dotnet publish -c Release -f netstandard2.0
Remove-Item -Force -Recurse .\bin\Release\netstandard2.0\publish\runtimes\
Then put the libraries of .\bin\Release\netstandard2.0
into your asset folder.
If you need altcoins support, use the same step but with cd NBitcoin/NBitcoin.Altcoins
instead.
If you want to use .NET Core, first install .NET Core as documented here.
Then:
mkdir MyProject
cd MyProject
dotnet new console
dotnet add package NBitcoin
dotnet restore
Then edit your Program.cs:
using System;
using NBitcoin;
namespace _125350929
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
}
}
}
You can then run with
dotnet run
NBitcoin notably includes:
NBitcoin is inspired by Bitcoin Core code but provides a simpler object oriented API (e.g., new Key().PubKey.Address.ToString() to generate a key and get the associated address). It relies on the BouncyCastle cryptography library instead of OpenSSL, yet replicates OpenSSL bugs to guarantee compatibility. NBitcoin also ports the integrality of Bitcoin Core unit tests with their original data in order to validate the compatibility of the two implementations.