# Local development

# Prerequisites

For the development environment you need to install these tools:

# Dependencies

To execute tests and run the project for debugging, you need to run a number of dependencies.

We wrapped all our dependencies in a docker-compose file that you can use to bootstrap the development environment: The file BTCPayServer.Tests/docker-compose.yml can be used to spin everything up:

git clone https://github.com/btcpayserver/btcpayserver.git
cd btcpayserver/BTCPayServer.Tests
docker-compose up dev

# Which IDE?

We recommend using Visual Studio Code (cross platform) or Visual Studio 2019 (Windows Only) or Rider (cross platform). You can of course use VIM if you are hardcore, .NET Core is command-line environment friendly.

Visual Studio Code, Visual Studio and Rider will run the launch profile Bitcoin. This will run a BTCPayServer instance connecting to the services in your Docker service, so you can easily debug and step through the code.

# Build configuration

A build configuration defines how to build BTCPay Server. For example, whether to include some source files, whether to optimize for debugging or performance.

There are several build configurations:

  • Debug
  • Release
  • Altcoins-Debug
  • Altcoins-Release

How to use a different one during your local development depends on your IDE. By default Debug is used, this is a Bitcoin only build excluding any altcoin dependencies. How to use a different one during your local development depends on your IDE.

You can select which build to use via the -c switch in dotnet command line. If you use command line and want to run a Release build:

dotnet run -c Release

# Launch profiles

When you start BTCPay Server locally for local development, it needs the right parameter so it can connect to the development time dependencies in the docker-compose file.

Those parameters are wrapped into the dotnet concept of launch profile.

The launch profiles are specified in the launchSettings.json.

There are currently three launch profiles:

  • Bitcoin
  • Bitcoin-HTTPS
  • Altcoins-HTTPS

By default, Bitcoin is used. How to use a different one during your local development depends on your IDE.

If you use command line, dotnet run allows you to select the launch profile of your choice:

dotnet run --launch-profile Bitcoin

# Running tests

Running tests is functioning in the exact same way as running the development time BTCPay Server.

cd BTCPayServer.Tests
dotnet test

The concept of launch profile does not apply for tests, but the concept of build configuration does. For example, if I want to run tests on the Release build:

dotnet test -c Release

The tests are already configured to use the development time dependencies in the docker-compose presented earlier.

You can use the --f (filter) switch to run a specific test.

If you use an IDE, consult your IDE documentation to run tests or switch to different configurations.

# Altcoin support development

By default, your IDE or simple dotnet run will use Bitcoin launch profile on Debug build.

  • This means that BTCPay Server will be hosted on a local HTTP port, building without altcoin support,
  • Run BTCPay Server to connect to Bitcoin only dependencies specified in BTCPayServer.Tests/docker-compose.yml.

If you want to develop with altcoins support you need to use the Altcoins-HTTPS launch profile, on the Altcoins-Debug build, and run the BTCPayServer.Tests/docker-compose.altcoins.yml.

If using command line:

cd BTCPayServer.Tests
docker-compose -f docker-compose.altcoins.yml up dev
cd ../BTCPayServer
dotnet run -c Altcoins-Debug --launch-profile Altcoins-HTTPS

For tests

cd BTCPayServer.Tests
dotnet test -c Altcoins-Debug

# HTTPS support for local development

Some browser security features may require that you use HTTPS to be properly tested.

In this case, use Bitcoin-HTTPS (or Altcoin-HTTPS) launch profile. This will create a self signed certificate for your development purpose.

However, your browser will not trust it, making it difficult to debug.

You can instruct your OS to trust this development time certificate by running:

dotnet dev-certs https --trust

# Videos

For more information check out these videos:

and these notes:

# How to manually test payments

# Using the test bitcoin-cli

You can call bitcoin-cli inside the container with docker exec. For example, if you want to send 0.23111090 to mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf:

./docker-bitcoin-cli.sh sendtoaddress "mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf" 0.23111090

If you are using Powershell:

.\docker-bitcoin-cli.ps1 sendtoaddress "mohu16LH66ptoWGEL1GtP6KHTBJYXMWhEf" 0.23111090

You can also generate blocks:

.\docker-bitcoin-generate.ps1 3

# Using the test litecoin-cli

Same as bitcoin-cli, but with .\docker-litecoin-cli.ps1 and .\docker-litecoin-cli.sh instead.

# Using the test lightning-cli

If you are using Linux:

./docker-customer-lightning-cli.sh pay lnbcrt100u1pd2e6uspp5ajnadvhazjrz55twd5k6yeg9u87wpw0q2fdr7g960yl5asv5fmnqdq9d3hkccqpxmedyrk0ehw5ueqx5e0r4qrrv74cewddfcvsxaawqz7634cmjj39sqwy5tvhz0hasktkk6t9pqfdh3edmf3z09zst5y7khv3rvxh8ctqqw6mwhh

If you are using Powershell:

.\docker-customer-lightning-cli.ps1 pay lnbcrt100u1pd2e6uspp5ajnadvhazjrz55twd5k6yeg9u87wpw0q2fdr7g960yl5asv5fmnqdq9d3hkccqpxmedyrk0ehw5ueqx5e0r4qrrv74cewddfcvsxaawqz7634cmjj39sqwy5tvhz0hasktkk6t9pqfdh3edmf3z09zst5y7khv3rvxh8ctqqw6mwhh

If you get this message:

{ "code" : 205, "message" : "Could not find a route", "data" : { "getroute_tries" : 1, "sendpay_tries" : 0 } }

Please, run the test CanSetLightningServer, this will establish a channel between the customer and the merchant, then, retry.

# FAQ

docker-compose up dev failed or tests are not passing, what should I do?

  1. Run docker-compose down --v (this will reset your test environment)
  2. Run docker-compose pull (this will ensure you have the lastest images)
  3. Run again with docker-compose up dev

If you still have issues, try to restart docker.