1 Star 0 Fork 0

超级大富 / NBitcoin

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

NBitcoin

Join the chat at https://gitter.im/MetacoSA/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 gitter 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.

Useful link for a free IDE :

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

The MIT License (MIT) Copyright (c) 2021 Metaco SA Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
C#
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/superbigfu/NBitcoin.git
git@gitee.com:superbigfu/NBitcoin.git
superbigfu
NBitcoin
NBitcoin
master

搜索帮助