Code Monkey home page Code Monkey logo

bitcoin-payment-microservice's Introduction

Micro Bitcoin Payment Service

A micro service for adding bitcoin payment to your node application. using node 8.0

Prerequisites

To install this module you need to have node installed in your loacl machine and also npm and/or yarn.

Testing

To run a unit test use the following command:

  npm run test

Usage

To use with the micro service you need to install some modules first with:

  npm install --save bitcoin-payment-mircoservice

Or you use yarn to install the package:

 yarn add bitcoin-payment-mircoservice

then in your javascript file add

  const bitcoinPayment = require('bitcoin-payment-mircoservice')

To get the current bitcoin balance of an address use:

 const balance =  bitcoinPayment.getBalance(address) // returns address balance
 console.log('bitcoin Balance', balance)

returns

  bitcoin Balance 0.009797

To generate a new bitcoin address

  const address = bitcoinPayment.createAddress() // returns a bitcoin address with private key
  console.log(address)

returns

 {
   address: '1K3QovFjbXG9HMYSfTE8WMc7EHhhpJSGwT',
   privateKey: 'achgjxsdvhjahkjlxkdcbazagshkjlskncvgshjasluyihkjaknjxs'
 }
 ** NOTE: Please always secure your private key

To send Bitcoin to an address

 sendBTC (paperWallet, toAddress, amount, network) =>  transactionID
 // paperWallet - Generated address with private key to validate the transaction
 // amount -  amount to be sent in satoshi
 // toAddress - Bitcoin address to receive the amount
 // network - which could either 'testnet' or 'livenet/mainnet'

To listen to an address on a network for a transaction

  bitcoinPayment.listenToLiveTransaction(address) => tx

Will trigger the event in real time if a payment is done to that address:

 Transaction detected! { address: '138WJKb1mXbkRGNpyMVEZ9EsoXjMEvJfT4',
 amount: 381000 }

### Built with
  • Node Js - javascript runtime engine
  • Bitcoin-live-transactions NPM package
  • Bitcoinjs-lib from bitcoinjs
  • Bitcore-lib from bitcore-lib
  • Bitcore-explorers from Bitcore-explorers
  • Axios

bitcoin-payment-microservice's People

Contributors

bensigo 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.