NBitcoin

用于.NET框架的综合比特币库。(Comprehensive Bitcoin library for the .NET framework.)

  • Owner: MetacoSA/NBitcoin
  • Platform: Android, iOS, Windows, WP
  • License:: MIT License
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

NBitcoin

NBitcoin是.NET平台上最完整的比特币库。它实现了所有最相关的比特币改进建议(BIPs)。它还提供对比特币原语的低级访问,因此您可以轻松地在其上创建应用程序。加入我们的 gitter聊天室。 它可以在Windows,Mac和Linux上使用Xamarin,Unity,.NET Core或CLR。 (如果你需要的话,移植到Unity应该不会那么难)

最好的文档是我们的电子书和出色的单元测试。以下还有一些资源。

如何使用?

Install-Package NBitcoin

访问 NuGet网站获取更多信息。

这些软件包支持:

  • 完整功能:Windows桌面应用程序,Mono Desktop应用程序和平台支持的 .NET Standard 1.3 (.NET Core,Xamarin IOS,Xamarin Android,UWP等)。
  • 功能有限:支持 .NET Standard 1.1 的平台(Windows Phone, Windows 8.0应用程序)。

要自己编译它,你可以通过git clone,打开项目并在Visual Studio中点击编译按钮。

如何开始?看看这篇 关于CodeProject 的一些基本的比特币操作或介绍NBitcoin视频

如何使用Litecoin?

安装包NBitcoin.Litecoin

这是一个轻量级包,包含Litecoin mainnet和testnet的相应 Network 实例。 信息来源

如何使用我自己的区块链?

如果您的加密货币与比特币相似,请查看我们如何将 litecoin整合到NBitcoin

如何在Unity中使用

在命令提示符下:

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\

然后将 .\bin\Release\netstandard2.0 的库放入资产文件夹。

如果您需要山寨币支持,请使用相同的步骤,但使用cd NBitcoin/NBitcoin.Altcoins。

如何在.NET Core中使用

如果您想使用.NET Core,请首先安装.NET Core ,如此处所述

然后:

mkdir MyProject
cd MyProject
dotnet new console
dotnet add package NBitcoin
dotnet restore

然后编辑你的Program.cs:

using System;
using NBitcoin;
namespace _125350929
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World! " + new Key().GetWif(Network.Main));
        }
    }
}

然后你可以运行

dotnet run

我们建议您使用 Visual Studio Code 作为项目的编辑器。

描述

NBitcoin值得注意的包括:

  • 支持Stealth,Open Asset和所有标准交易的 TransactionBuilder
  • 完整的脚本评估和解析
  • RPC客户端
  • Rest客户
  • SPV电子钱包实施带样本
  • 解析标准脚本并创建自定义脚本
  • 块,交易和脚本的序列化
  • 使用私钥(支持简洁签名)对证书进行签名和验证
  • 布隆过滤器和部分梅克尔树
  • 隔离见证( BIP 141BIP 143 BIP 144 )
  • Bech32具有错误检测功能的segwit地址实现 BIP 173
  • 用于生成确定性键的助记码( BIP 39 ),信用于 Thasshiznets
  • 分层确定性钱包( BIP 32
  • 付款协议( BIP 70
  • 付款网址( BIP 21 BIP 72
  • 双因子键( BIP 38
  • 隐身地址(另请参阅codeproject

NBitcoin受比特币核心代码的启发,但提供了一个更简单的面向对象的API(例如,新的Key().PubKey.Address.ToString()来生成密钥并获得关联的地址)。它依赖于BouncyCastle加密库而不是OpenSSL,但复制OpenSSL缺陷以保证兼容性。 NBitcoin还将比特币核心单元测试与其原始数据的完整性结合起来,以验证两种实现的兼容性。

NBitcoin根据麻省理工学院许可证获得许可,我们鼓励您使用它来探索,学习,调试,播放,分享和为比特币和其他Metaco服务创建软件。

有用的文档:

请使用github问题提出问题或反馈。对于保密请求或具体要求,请通过 Metaco支持与我们联系。

免费IDE的有用链接:

Visual Studio社区版: https://www.visualstudio.com/products/visual-studio-community-vs

Main metrics

Overview
Name With OwnerMetacoSA/NBitcoin
Primary LanguageC#
Program languageC# (Language Count: 3)
PlatformAndroid, iOS, Windows, WP
License:MIT License
所有者活动
Created At2014-04-09 12:22:52
Pushed At2025-06-02 08:34:42
Last Commit At2025-06-02 17:34:36
Release Count980
Last Release Namev8.0.18 (Posted on 2025-06-02 10:11:26)
First Release Namev1.0.4.1 (Posted on 2014-05-31 17:22:33)
用户参与
Stargazers Count1.9k
Watchers Count166
Fork Count856
Commits Count3.5k
Has Issues Enabled
Issues Count540
Issue Open Count90
Pull Requests Count546
Pull Requests Open Count24
Pull Requests Close Count150
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

NBitcoin

Join the chat at https://chat.btcpayserver.org/btcpayserver/channels/nbitcoin
Build status

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. Join us in our mattermost chat room.
It works on Windows, Mac and Linux with Xamarin, Unity, .NET Core or CLR. (Porting to Unity should not be that hard if you need it)

The best documentation available is our eBook, and the excellent unit tests. There are also some more resources below.

You can also browse the API easily through the API reference.

How to use ?

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.

Go on the NuGet website for more information.

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).
  • With limited features: platforms supported by .NET Standard 1.1 (Windows Phone, Windows 8.0 apps).

To compile it by yourself, you can git clone, open the project and hit the compile button in Visual Studio.

How to get started?

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.

How to use with Altcoins ?

Install-Package NBitcoin.Altcoins

Find more information here.

How to debug in NBitcoin source code?

When a new version of NBitcoin, NBitcoin.Altcoins or NBitcoin.TestFramework is released on Nuget, we also upload a separate symbol package (snupkg) with SourceLink enabled. This is enabled from version 4.1.1.73.

This means that it is possible to debug into NBitcoin code, and the source will be fetched transparently from github.

This works on both Visual Studio Code and Visual Studio for Windows.

Debug inside source with Visual Studio

You need to run at least Visual Studio 15.9.
Then, you need to:

  • Go in Tools / Options / Debugging / General and turn off Enable Just My Code.
  • Go in Tools / Options / Debugging / Symbols and add https://symbols.nuget.org/download/symbols to the Symbol file (.pdb) locations, make sure it is checked.

You should also check Microsoft Symbol Server or your debugging experience in visual studio will be slowed down.

Now you can Debug your project and step inside any call to NBitcoin.

Debug inside source with Visual Studio Code

Inside your launch.json, add the following to .NET Core Launch (console) configuration:

"justMyCode": false,
"symbolOptions": {
    "searchPaths": [ "https://symbols.nuget.org/download/symbols" ],
    "searchMicrosoftSymbolServer": true
},

Now you can Debug your project and step inside any call to NBitcoin.

How to use with my own blockchain?

Find more information here.

How to use in Unity?

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.

How to use in .NET Core

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

We advise you to use Visual Studio Code as the editor for your project.

Description

NBitcoin notably includes:

  • A TransactionBuilder supporting Stealth, Open Asset, and all standard transactions
  • Full script evaluation and parsing
  • A RPC Client
  • A Rest Client
  • The parsing of standard scripts and creation of custom ones
  • The serialization of blocks, transactions and scripts
  • The signing and verification with private keys (with support for compact signatures) for proving ownership
  • Bloom filters and partial merkle trees
  • Segregated Witness (BIP 141, BIP 143, BIP 144)
  • Bech32 segwit address implementation with error detection BIP 173
  • Mnemonic code for generating deterministic keys (BIP 39), credits to Thasshiznets
  • Hierarchical Deterministic Wallets (BIP 32)
  • Payment URLs (BIP 21)
  • Full Bitcoin P2P implementation with SOCKS5 support for connecting through Tor
  • A C# implementation of secp256k1

Please read our ebook to understand the capabilities.

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.

NBitcoin is licensed under the MIT License and we encourage you to use it to explore, learn, debug, play, share and create software for Bitcoin and with other Metaco services.

How to connect use a SOCKS5 proxy to connect to a Bitcoin node?

Here an example which assume you run Tor with SOCKS5 proxy on port 9050.

var connectionParameters = new NodeConnectionParameters();
connectionParameters.TemplateBehaviors.Add(new SocksSettingsBehavior(Utils.ParseEndpoint("localhost", 9050)));
Node node = await Node.ConnectAsync(Network.Main, "7xnmrhmkvptbcvpl.onion:8333", connectionParameters);
node.VersionHandshake();

Some OSS projects using NBitcoin

Useful doc :

Please, use github issues for questions or feedback. For confidential requests or specific demands, contact us on Metaco support.

Visual Studio Community Edition : https://www.visualstudio.com/products/visual-studio-community-vs