#bitcoin #send-receive #payjoin #bip78

app payjoin-cli

A command-line Payjoin client for Bitcoin Core

4 releases

0.0.5-alpha Mar 20, 2024
0.0.4-alpha Feb 23, 2024
0.0.3-alpha Feb 2, 2024
0.0.2-alpha Dec 14, 2023
0.0.1-alpha Nov 29, 2023

#2945 in Magic Beans

Download history 1/week @ 2024-01-31 4/week @ 2024-02-14 150/week @ 2024-02-21 21/week @ 2024-02-28 1/week @ 2024-03-06 3/week @ 2024-03-13 114/week @ 2024-03-20 7/week @ 2024-03-27 9/week @ 2024-04-03

134 downloads per month

MITNFA license

245KB
4.5K SLoC

payjoin-cli

A command-line payjoin client for bitcoind in rust

The payjoin-cli client enables sending and receiving of BIP 78 Payjoin V1 and Draft BIP Payjoin V2 transactions. By default it supports Payjoin V1, and the v2 feature sends and receives both since the protocol is backwards compatible. The implementation is built on Payjoin Dev Kit.

While this code and design has had significant testing, it is still alpha-quality experimental software. Use at your own risk. Independent audit is welcome.

Install payjoin-cli

cargo install payjoin-cli --version 0.0.5-alpha

Get a list of commands and options:

payjoin-cli --help

Either pass config options from cli, or manually edit a config.toml file within directory you run payjoin-cli from. Configure it like so:

# config.toml
bitcoind_cookie = "/tmp/regtest1/bitcoind/regtest/.cookie"
# specify your wallet via rpchost connection string
bitcoind_rpchost = "http://localhost:18443/wallet/boom"

Your configuration details will vary, but you may use this as a template.

Test Payjoin 2

Install payjoin-cli with the V2 feature

cargo install payjoin-cli --version 0.0.5-alpha --features v2

V2 Configuration

In addition to the rpc configuration above, specify relevant ohttp and payjoin directory configuration as follows:

# config.toml
...
# a production payjoin directory server
pj_endpoint="https://payjo.in"
# payjo.in's ohttp_keys can now be fetched rather than configured ahead of time
 # an ohttp relay with ingress to payjo.in
ohttp_relay="https://pj.bobspacebkk.com"

Asynchronous Operation

Send and receiver state is saved to json files in the directory from which payjoin-cli is run. Once a send or receive session is started, it may resume using the --retry argument if the payjoin has not yet complete.

payjoin-cli --retry <subcommmand>

<subcommand> should be either send or receive followed by the same arguments as the first time it was called.

Manual End to End Regtest Testing

Test Receive

Set up 2 local regtest wallets and fund them. This example uses "boom" and "ocean"

Determine the RPC port specified in your bitcoind's bitcoin.conf file. 18443 is the default. This can be set like so:

rpcport = 18443

From the directory you'll run payjoin-cli, assuming "boom" is the name of the receiving wallet, 18443 is the rpc port, and you wish to request 10,000 sats run:

RUST_LOG=debug cargo run --features=danger-local-https -- -r "http://localhost:18443/wallet/boom" receive 10000

The default configuration listens for payjoin requests at http://localhost:3000 and expects you to relay https requests there. Payjoin requires a secure endpoint, either https and .onion are valid. In order to receive payjoin in a local testing environment one may enable the danger-local-https feature which will provision a self-signed certificate and host the https://localhost:3000 endpoint. Emphasis on HTTPS.

This will generate a payjoin capable bip21 URI with which to accept payjoin:

BITCOIN:BCRT1QCJ4X75DUNY4X5NAWLM3CR8MALM9YAUYWWEWKWL?amount=0.00010&pj=https://localhost:3000

Test Send

Create a "sender" directory within payjoin-cli. Open a new terminal window and navigate to this directory.

Note: A wallet cannot payjoin with itself, one needs separate wallets.

Create another config.toml file in the directory the sender will run from and configure it as you did previously, except replace the receiver wallet name with the sender

Using the previously generated bip21 URI, run the following command from the sender directory:

 RUST_LOG=debug cargo run -- send <BIP21> --fee-rate <FEE_SAT_PER_VB>

You should see the payjoin transaction occur and be able to verify the Partially Signed Bitcoin Transaction (PSBT), inputs, and Unspent Transaction Outputs (UTXOs).

Congrats, you've payjoined!

Dependencies

~19–35MB
~522K SLoC