GithubHelp home page GithubHelp logo

dabura667 / node-btcpay Goto Github PK

View Code? Open in Web Editor NEW

This project forked from btcpayserver/node-btcpay

0.0 2.0 0.0 62 KB

BTCPay NodeJS client

License: MIT License

TypeScript 96.71% JavaScript 3.29%

node-btcpay's Introduction

node-btcpay

Install

npm i btcpay

Private key generation

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

>>> <Key priv: XXXXXXX pub: null >

Store the value of "priv" in a save 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 save 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(<BCTPAYURL>, 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))

node-btcpay's People

Contributors

danlutz avatar junderw avatar nicolasdorier avatar shesek avatar takinbo avatar uter1007 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.