BitPay C# .NET Library

Implement blockchain payments on your e-commerce website using BitPay's C# .NET Library.

Using the BitPay .NET Library

This library provides a convenient abstraction of BitPay's cryptographically-secure API and allows payment gateway developers to focus on payment flow/e-commerce integration rather than on the specific details of client-server interaction using the API. This library optionally provides the flexibility for developers to have control over important details, including the handling of private keys needed for client-server communication.

It also implements BitPay's remote client authentication and authorization strategy. No private or shared-secret information is ever transmitted over the wire.


You must have a BitPay merchant account to use this library. It's free to sign-up for a BitPay merchant account.

If you need a test account, please visit and register for a BitPay merchant test account. Please fill in all questions, so you get a fully working test account. If you are looking for a testnet bitcoin wallet to test with, please visit and create a new wallet. If you need testnet bitcoin please visit a testnet faucet, e.g. or

For more information about testing, please see


You can find and download this package from NuGet Package Manager.
Make sure you have the latest version to avoid implementation and security issues.

Handling your client private key

Each client paired with the BitPay server requires a ECDSA key. This key provides the security mechanism for all client interaction with the BitPay server. The public key is used to derive the specific client identity that is displayed on your BitPay dashboard. The public key is also used for securely signing all API requests from the client. See the BitPay API for more information.

The private key should be stored in the client environment such that it cannot be compromised. If your private key is compromised you should revoke the compromised client identity from the BitPay server and re-pair your client, see the API tokens for more information.

The BitPay.Net Setup utility helps to generate the private key, as well as a environment file formatted in JSON which contains all configuration requirements, that should be stored in the client local file system. It is not recommended to transmit the private key over any public or unsecure networks.

Follow the guide BitPay.Net Setup utility guide that assist you to create the environment file which you will be able to modify it, either manually or by using the BitPay.Net Setup utility, later on by asking you to provide the path to your existing JSON file.

The environment file can be either generated by the BitPay.Net Setup utility or created manually by copying the following Json structure:

  "BitPayConfiguration": {
    "Environment": "",
    "EnvConfig": {
      "Test": {
        "PrivateKeyPath": "",
        "ApiTokens": {
          "pos": "",
          "merchant": "",
          "payroll": ""
      "Prod": {
        "PrivateKeyPath": "",
        "ApiTokens": {
          "pos": "",
          "merchant": "",
          "payroll": ""

Initializing your BitPay client

Once you have the environment file (JSON previously generated) you can initialize the client on two different ways:

// Provide the full path to the env file which you have previously stored securely.

BitPay bitpay = new BitPay("BitPay.config.json");

// Provide a IConfiguration Interface containing the same structure as in the json file.

var configuration = new ConfigurationBuilder()
    .AddJsonFile("BitPay.config.json", false, false)

BitPay bitpay = new BitPay(configuration);

// Initialize with separate variables.

BitPay bitpay = new BitPay(
    new Env.Tokens(){
        POS = "AvJdGrEqTW9HVbqaQDhWHRacHYgfgxsJit9zabAnrJaK",
        Merchant = "CE2WRSEExNFA4YdQyyDJmgVAot9FgXvXbo752TGA7eUj",
        Payout = "9pJ7fzW1GGeucVMcDrs7HDQfj32aNATCDnyY6YAaHUNo"

Pair your client with BitPay

Your client must be paired with the BitPay server. The pairing initializes authentication and authorization for your client to communicate with BitPay for your specific merchant account.

Pairing is accomplished by having the BitPay.Net Setup utility request a pairing code from the BitPay server. Meanwhile a new pairing code is generated, the BitPay.Net Setup utility will ask you to activate it in your BitPay account. It will also store the paired token in the environment file.

The pairing code is then entered into the BitPay merchant dashboard for the desired merchant. Your interactive authentication at provides the authentication needed to create finalize the client-server pairing request.

Create an invoice

Invoice invoice = bitpay.createInvoice(new Invoice(50.0, "USD")).Result;

String invoiceUrl = invoice.getURL();

String status = invoice.getStatus();

Create an invoice (extended)

You can add optional attributes to the invoice. Atributes that are not set are ignored or given default values.

Invoice invoice = new Invoice(100.0, "USD");
invoice.BuyerName = "Satoshi";
invoice.BuyerEmail = "";
invoice.FullNotifications = true;
invoice.NotificationEmail = "";
invoice.PosData = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";

invoice = this.bitpay.createInvoice(invoice).Result;

Retrieve an invoice

Invoice invoice = bitpay.getInvoice(invoice.getId()).Result;

Get exchange rates

You can retrieve BitPay's BBB exchange rates.

Rates rates = this.bitpay.getRates().Result;

double rate = rates.getRate("USD");


See also the xUnit test project for more examples of API calls.

Integration Options
BitPay C# .NET Library


View on GitHubview on nuget

Get Started with the BitPay C# .NET Library integration