Skip to content

Instantly share code, notes, and snippets.

@AdamISZ
Last active April 3, 2023 20:07
Show Gist options
  • Save AdamISZ/32b948bb1c725ce12230001c503df401 to your computer and use it in GitHub Desktop.
Save AdamISZ/32b948bb1c725ce12230001c503df401 to your computer and use it in GitHub Desktop.
How to set up a local dev environment on regtest with btcpayserver and joinmarket for interoperability testing of payjoin

Setup paying hot wallet btcpayserver to joinmarket all on one machine, on regtest:

  1. Follow installation instructions from scratch as per: https://docs.btcpayserver.org/LocalDevelopment/ (note, there is another setup description, but it is specifically for coding and debugging, using visual studio, here: https://docs.btcpayserver.org/Contribute/ContributeDev/ContributeDevCode/#visual-studio-setup)

  2. after the docker-compose up dev command specified there, run dotnet run --launch-profile Bitcoin from BTCPayServer directory (should not need to change any config)

  3. Load http://127.0.0.1:14142 to get the BTCPayServer UI

  4. Create an Admin account (check the option) with a random email and password. New screen should show 'Regtest' and 'Server Settings'.

  5. In Server Settings allow hot wallets as per https://docs.btcpayserver.org/HotWallet/#requirements-for-hot-wallet

  6. Create a Store, then edit the HD settings, choose "New/Existing seed". Also enable Payjoin in the same settings page.

  7. Edit the bitcoin rpc settings in your joinmarket test config file: use the settings in the BTC regtest container, which you can find by starting a shell inside the bitcoin container:

root@8c04a092756a:/# cat /data/bitcoin.conf 
regtest=1
[regtest]
printtoconsole=1
rpcallowip=::/0
rpcuser=ceiwHEbqWI83
rpcpassword=DwubwWsoo3
rpcport=43782
rpcbind=0.0.0.0:43782
port=39388
whitelist=0.0.0.0/0
zmqpubrawblock=tcp://0.0.0.0:28332
zmqpubrawtx=tcp://0.0.0.0:28333
deprecatedrpc=signrawtransaction
fallbackfee=0.0002
root@8c04a092756a:/#
  1. Edit the native setting to true so you can use native bech32 regtest wallet

  2. Generate a wallet on command line: python wallet-tool.py --datadir=. generate and note the seed.

  3. Enter that seed into the HD configuration for the store, which will set the wallet. Enter the path m/84'/1'/0' for the 0th account in the Wallet Settings account key path in Btcpayserver (remember 1 for coin type because regtest/testnet).

  4. Generate a receiving address in btcpayserver (bcrt1..)

  5. Use the tools in BTCPayServer.Tests to add funds to that wallet:

waxwing@here~/code/btcpayserver/BTCPayServer.Tests$ sudo docker ps -q --filter label=com.docker.compose.project=btcpayservertests --filter label=com.docker.compose.service=bitcoind
9155dbf0df0d
waxwing@here~/code/btcpayserver/BTCPayServer.Tests$ sudo docker exec -ti 9155dbf0df0d bitcoin-cli -datadir="/data" getnewaddress
bcrt1q7kvxw58vnv3zq69j0k5sf8rwkdzlze43xhs7rg
waxwing@here~/code/btcpayserver/BTCPayServer.Tests$ sudo docker exec -ti 9155dbf0df0d bitcoin-cli -datadir="/data" generatetoaddress 3 "bcrt1q7kvxw58vnv3zq69j0k5sf8rwkdzlze43xhs7rg"
[
  "4aee801beea0eab877e96b34866870d48a4ec042475e9e934e69bdfb21719d81",
  "06527bfe2667f7731b0899a23ff325fd39f65a3514f6395c64bf451d351eac28",
  "51d769ab70a7d94a8ef490f3cf7853924b93a96cd0dd928937fdbef2aa073763"
]
waxwing@here~/code/btcpayserver/BTCPayServer.Tests$ sudo ./docker-bitcoin-cli.sh sendtoaddress "bcrt1q65vjujsdkvnz94f39z39v6wdl2pfp36ppvr947" 0.33
919069890f4b93ecec229bfe85fea2aea0d6585fd438882ac1a8bce022629e1c
waxwing@here~/code/btcpayserver/BTCPayServer.Tests$ sudo docker exec -ti 9155dbf0df0d bitcoin-cli -datadir="/data" generatetoaddress 3 "bcrt1q7kvxw58vnv3zq69j0k5sf8rwkdzlze43xhs7rg"
[
  "6b8ce7c6175aa240516ca22d506c73efe24dfcdfdd59f0c10b06400ea26304e6",
  "6bdd08f76b17060b43202c5eac6f8c050facd9f746c51d87dab818a27814713c",
  "41494fbdcf21973111a04a3bde05e9591ee5b54f7031b56e69a47800d2640e1b"
]
  1. Make another wallet in Joinmarket, same method as before; add funds to it using the above commands.

  2. docker is now running Tor on the control port, need to run another Tor instance on host machine:

edit sudo vi /etc/tor/torrc - change the ControlPort and the SocksPort to not conflict with defaults.

Restart tor (just use tor rather than sudo service tor start because the latter uses defaults(?)).

Edit the joinmarket.cfg PAYJOIN settings:

[PAYJOIN]
onion_socks5_host = localhost
onion_socks5_port = 9053
tor_control_host = localhost
tor_control_port = 9052
  1. Start the receive-payjoin script in joinmarket: python receive-payjoin.py --datadir=. recvbpay2.jmdat -m0 0.07 or similar

  2. Send the payment from btcpayserver in "Send" tab of wallet. Click to enter BIP21 URI from JM. Sign options: sign with hot wallet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment