🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

blockchain-payments

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockchain-payments

Blockchain.info payment api module

0.1.9
latest
Source
npm
Version published
Maintainers
1
Created
Source

Install

npm install blockchain-payments

About

Blockchain.info payment api (v2) module

Example

Creation of an address

const BlockchainPayments = require("blockchain-payments");
const express = require("express");
const app = express();

const xpub = "xpub"; // xpub
const key = "key"; // blockchain key
const notifySecret = "secret"; // secret key for notification

const blockchain = new BlockchainPayments(xpub, key, notifySecret);

// Create an address for the payment
app.post('/payments/bitcoin/address/', (req, res, next) => {    
  blockchain.createAddress({
      callback: 'http://example.com'
  }, {
      someCallbackField1: '1',
      someCallbackFieldw2: '2',
  }).then((data) => {
      console.log(data) // {address: ..., index: ..., callback: ...}
  })
});

Conversation of currencies

BlockchainPayments.toBTC(500, 'USD').then((amountInBTC) => {
    // converting USD(or other) to BTC;
});

Handling of a notification

const successHandler = (data, callback) => {
  // data === req.query    
  // save payment info into db e.t.c    
  // callback() or return promise
};

const errorHandler = (err, meta) => {
  // you can save something to a file, db e.t.c.
  // operation must be synchronous or in the background
};

let confirmationsCount = 8; // count of confirmations for acception, default 6

app.get('payments/notification/', blockchain.notify(successHandler, errorHandler, confirmationsCount));

Description

You can write custom notification handler, but library version includes data/authentication validation and automatically sends all headers in the necessary format

API

.constructor(xpub, key, notifySecret, [notifyCallback])

you can find xpub and key in your blockchain account, notifySecret you have to come up yourself

.createAddress(query, [callbackQuery])

returns promise, creates bitcoin address for client payment
you can set callback url query params with callbackQuery as js object

.notify(fn, onError, [confirmationsCount])

notification handler, it is "connect" middleware

Class methods

.toBTC(amount, currency)

converts an amount from a given currency to BTC, returns promise

Keywords

blockchain

FAQs

Package last updated on 08 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts