[BREAKGLASS] BTCPay NodeJS client
Go to file
dependabot[bot] 48ac61f1e7
Some checks failed
Run Tests / run-test (push) Has been cancelled
Run Tests / coverage-check (push) Has been cancelled
Run Tests / lint-check (push) Has been cancelled
Run Tests / format-check (push) Has been cancelled
Bump minimist from 1.2.5 to 1.2.6 (#70)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-03 11:45:24 +00:00
.github/workflows Add Github Actions CI (#55) 2021-02-04 09:53:34 +00:00
docker Docker for testing (#42) 2021-02-02 16:20:50 +00:00
src Bump packages and run formatter (#62) 2021-05-11 15:03:09 +00:00
tests Bump packages and run formatter (#62) 2021-05-11 15:03:09 +00:00
.gitignore Add tests (Need pairingcode fix) 2019-05-21 09:57:25 +09:00
jest.json Add tests (Need pairingcode fix) 2019-05-21 09:57:25 +09:00
LICENSE initial version 2018-04-16 18:05:21 +00:00
package-lock.json Bump minimist from 1.2.5 to 1.2.6 (#70) 2022-12-03 11:45:24 +00:00
package.json bump version to v0.2.5 (#63) 2021-05-11 15:34:54 +00:00
README.md Update README.md 2022-02-08 12:42:06 +09:00
tsconfig.json Fix some syntax 2019-05-21 09:57:15 +09:00
tslint.json Fix some syntax 2019-05-21 09:57:15 +09:00

⚠️ This package is deprecated, BTCPay Server is exposing a new, more complete and easy to use API called Greenfield. Check the doc

node-btcpay

Install

npm i btcpay

Private key generation

  • Generate and save private key:
$ node -p "require('btcpay').crypto.generate_keypair().getPrivate('hex')"
XXXXXXXXXXXXXXXXXXXXX

Store the printed value in a safe place, e.g. environment variables

Pairing

After generating your private key, you have to pair your client with your BTCPay store:

  • On BTCPay Server > Stores > Settings > Access Tokens > Create a new token, (leave PublicKey blank) > Request pairing
  • Copy pairing code:
  • Pair client to server and save returned token:
# Replace the BTCPAY_XXX envirnoment variables with your values and run:

$ [space] BTCPAY_URL=https://mydomain.com/ BTCPAY_KEY=... BTCPAY_PAIRCODE=... node -e "const btcpay=require('btcpay'); new btcpay.BTCPayClient(process.env.BTCPAY_URL, btcpay.crypto.load_keypair(Buffer.from(process.env.BTCPAY_KEY, 'hex'))).pair_client(process.env.BTCPAY_PAIRCODE).then(console.log).catch(console.error)"

# (prepend the line with a space to prevent BTCPAY_KEY from being saved to your bash history)

>>> { merchant: 'XXXXXX' }

Store the value of "merchant" in a safe place, e.g. environment variables

Recreating a client

After pairing your client to the store, you can recreate the client as needed and use it in your code

const btcpay = require('btcpay')
const keypair = btcpay.crypto.load_keypair(new Buffer.from(<PRIVATEKEY>, 'hex'))

// Recreate client
const client = new btcpay.BTCPayClient(<BTCPAYURL>, keypair, {merchant: <MERCHANT>})

Get rates

Fetches current rates from BitcoinAverage (using your BTCPayServer)

client.get_rates(['BTC_USD'], <STOREID>)
  .then(rates => console.log(rates))
  .catch(err => console.log(err))

The first argument accepts a comma-separated list of currency pair.

Create invoice

See BitPay Invoice API documentation

client.create_invoice({price: 20, currency: 'USD'})
  .then(invoice => console.log(invoice.url))
  .catch(err => console.log(err))

Get invoice

client.get_invoice(<invoice-id>)
  .then(invoice => console.log(invoice.status))
  .catch(err => console.log(err))