Coder Social home page Coder Social logo

nevtep / meteor.blockchain.info.websocket Goto Github PK

View Code? Open in Web Editor NEW

This project forked from joshuarossi/meteor.blockchain.info.websocket

2.0 2.0 1.0 6 KB

This is a simple wrapper for the Blockchain.info Websocket API. The goal is to make a super simple way for Meteor apps to listen to transaction info from the Bitcoin Blockchain.

Home Page: https://atmospherejs.com/mjr/blockchain-websockets

JavaScript 100.00%

meteor.blockchain.info.websocket's Introduction

Synopsis

This is a simple wrapper for the Blockchain.info Websocket API. The goal is to make a super simple way for Meteor apps to listen to transaction info from the Bitcoin Blockchain.

Installation

meteor add mjr:blockchain-websockets

Quick Start

Create some routes in a client/server JavaScript file: First you will create a new instance of the Blockchain object:

bc = new Blockchain()

Then you will connect to the websocket feed:

bc.connect()

Now you can subscribe to transaction involving a given Bitcoin address:

bc.addNewAddressSubscription(<bitcoin_address>)

Or you could subscribe to ALL transactions:

bc.subscribeAllTransactions()

If you have trouble, you can open up a meteor shell, and use the following to debug your connection:

bc.testTransaction()

To implement more than console logging messages (save to db, trigger other actions) you can override the "messageHandler" function, here is the current code:

bc.messageHandler = function(message){
    if (message.type === 'utf8') {
      console.log("> "+ message.utf8Data);
    }
  };

Here is an example transaction object:

{
"op":"utx",
"x":{
   "lock_time":0,
   "ver":1,
   "size":225,
   "inputs":[
      {
         "sequence":4294967295,
         "prev_out":{
            "spent":true,
            "tx_index":89879750,
            "type":0,
            "addr":"1Bp3FC6FD5QSX7d3shMGFJkKZfefZxaz9Z",
            "value":446292000,
            "n":1,
            "script":"76a9147696ae8aa64ef078199fbff413c9c15dfafa4da788ac"
         },
         "script":"473044022013b3d20efe024f74e2e57c5722e8de7302c061fe41517452764d0260972dd328022045902e1f574c36952a39a34bb90810e43dfbaad17cda27f78a0c540de79c7255012103ec1b41016b3ac94430573f55c2797d412d7169b5096402fe9317a93e852c5bdf"
      }
   ],
   "time":1433970007,
   "tx_index":89880810,
   "vin_sz":1,
   "hash":"b29a33468ca2ddbe03eb2f9e7eda21556fac62efe1309f93fd41e99172eb3f83",
   "vout_sz":2,
   "relayed_by":"212.71.238.204",
   "out":[
      {
         "spent":false,
         "tx_index":89880810,
         "type":0,
         "addr":"1BnSkJeb5hfbPhreKpPo95xUtoUBuq3zsZ",
         "value":5734000,
         "n":0,
         "script":"76a914764977e3bf32627ec99dbf7c80f2beb8b883258688ac"
      },
      {
         "spent":false,
         "tx_index":89880810,
         "type":0,
         "addr":"12Mu3QvHgrRH6dte7rAmh3GowebedAfyCS",
         "value":440548000,
         "n":1,
         "script":"76a9140eebe31c80517cdb2652a6fdfd4e369aff4ef93188ac"
      }
   ]
}
}

meteor.blockchain.info.websocket's People

Contributors

joshuarossi avatar nevtep avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

germanf

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.