A template for your own BTCPay Server plugin.
Learn more in our plugin documentation.
- .NET SDK 10.0 or later
- Git with submodule support
- Docker, for running the BTCPay Server development dependencies
First, clone this repository:
mkdir my-plugin && cd my-plugin
git clone --recurse-submodules https://github.com/btcpayserver/btcpayserver-plugin-template.git .If you already cloned without submodules, initialize them with:
git submodule update --init --recursiveMake sure that your submodules reference the latest stable version of BTCPay Server.
cd modules/btcpayserver
git fetch --tags
latest_tag=$(
git tag -l 'v[0-9]*.[0-9]*.[0-9]*' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V \
| tail -n 1
)
git checkout "$latest_tag"
cd ../..Update src/BTCPayServer.Plugins.Template/Plugin.cs's PluginDependency with the version of BTCPayServer that you fetched in latest_tag.
For renaming the plugin, choose a name following .NET assembly naming conventions: PascalCase, optionally separated by dots. For example: MyPlugin or MyCompany.MyPlugin.
Then replace all occurrences of BTCPayServer.Plugins.Template with PLUGIN_NAME.
Here is a script you can run to do this automatically:
PLUGIN_NAME="MyPlugin"
OLD_NAME="BTCPayServer.Plugins.Template"
export OLD_NAME PLUGIN_NAME
git grep -l -z "$OLD_NAME" -- . ':!submodules' | xargs -0 perl -pi -e 's/\Q$ENV{OLD_NAME}\E/$ENV{PLUGIN_NAME}/g'
git mv "src/$OLD_NAME" "src/$PLUGIN_NAME"
git mv "src/$PLUGIN_NAME/$OLD_NAME.csproj" "src/$PLUGIN_NAME/$PLUGIN_NAME.csproj"
git mv "tests/$OLD_NAME.Tests" "tests/$PLUGIN_NAME.Tests"
git mv "tests/$PLUGIN_NAME.Tests/$OLD_NAME.Tests.csproj" "tests/$PLUGIN_NAME.Tests/$PLUGIN_NAME.Tests.csproj"
git mv "$OLD_NAME.slnx" "$PLUGIN_NAME.slnx"Then update the plugin metadata in src/<YourPluginName>/<YourPluginName>.csproj:
ProductDescriptionVersion
Verify that the plugin builds:
dotnet buildFinally, clean up the remaining template project references.
Replace this README with documentation for your own plugin. Keep it user-centric. Document what the plugin does and how to configure it. We advise to include screenshots and video. Avoid developer-centric jargon.
You may also want to review and update:
- LICENSE
- package metadata in your plugin
.csproj
Switch origin to your own repository:
git remote set-url origin git@github.com:<your-github-user>/<your-plugin-repository>.gitIf you want to start your plugin without the template's git history, create a new initial commit:
git switch --orphan initial
git add -A
git commit -m "Initial commit"
git branch -M mainThen push it to your repository.
git push --force-with-lease origin mainRegister the plugin with the BTCPay Server development environment:
./plugin-register.shIt will configure BTCPay Server for loading your plugin during debug.
Start the BTCPay Server development dependencies:
cd submodules/btcpayserver/BTCPayServer.Tests
docker compose up -d devOpen the solution file in your IDE and use the BTCPayServer: Bitcoin-HTTPS launch profile. When the debugger starts BTCPay Server, it should load your plugin. A breakpoint in src/<YourPluginName>/Plugin.cs, such as inside Plugin.Execute, should be hit during startup.
The template starts with a minimal Plugin.cs class:
Register your services, controllers, hosted services, migrations, or other plugin components from Execute.
If your plugin needs Entity Framework or bundled project dependencies, see the commented examples in the plugin .csproj file.
You can take examples from other plugins and BTCPay Server's own system plugins in submodules/btcpayserver/BTCPayServer/Plugins.