bitsocket

Message Bus for Bitcoin

Examples Get Started Explorer Github

What does it do?

Bitsocket is a powerful bitcoin push notification service for building realtime bitcoin applications.

Bitsocket lets you subscribe to any pattern of realtime bitcoin transactions through Bitquery and build apps that are driven by the event.

It is 100% open source and designed to be decentralized.

Using bitsocket as a bitcoin message bus, it is possible to construct various bitcoin application architectures through message piping:

  1. Bitcoin App
    Build applications that listen to and run on various Bitcoin events
  2. Bitcoin App 3rd party API
    Build applications that listen to Bitcoin events and trigger 3rd party APIs
  3. Bitcoin App Bitcoin
    Build apps that listen to certain patterns of transactions, and then trigger another bitcoin transaction in response. Create a looping program on Bitcoin.
  4. App1 Bitcoin App2
    Create apps that communicate with one another through Bitcoin transactions. To communicate, App1 can send an immutable message to App2 by making a bitocin transaction, to which App2 is listening and triggers its own custom action in response. Like Inter-process calls (IPC), but for Bitcoin.

How does it work?


1. Transform

Bitsocket transforms every incoming raw bitcoin transaction into a structured format that can be filtered, transformed, and programmed, in realtime.

2. Eventify

All the clients plugged into bitsocket subscribe with their own application-specific filter powered by Bitquery, a Turing complete bitcoin query language. Bitsocket takes the transformed transaction object from the previous step and programmatically turns it into application-specific events in realtime.

3. Push

Each transformed event from the previous step is pushed to the corresponding application via SSE (Server Sent Events). The apps can be anything from a mobile app to web app to server side app to a hardware device.

Why is it powerful?


1. The Most Powerful Way to Listen to Bitcoin

Bitsocket lets you monitor realtime Bitcoin network like never before
  1. Write a query to filter EXACTLY the events you want
  2. From the ENTIRE bitcoin universe (not just a single wallet address or a transaction id. Everything.)

And it's as easy as using websockets (Actually it's SSE). Here's an example of an actual functional code:

// Write a bitquery
var query = {
  "v": 3, "q": { "find": {} }
}

// Encode it in base64 format
var b64 = btoa(JSON.stringify(query))

// Subscribe
var bitsocket = new EventSource('https://bitsocket.org/s/'+b64)

// Event handler
bitsocket.onmessage = function(e) {
  console.log(e.data)
}
Whenever there's a new transaction in bitcoin universe that matches the query filter specified by the query object, bitsocket pushes you the notification via SSE (server sent events).

2. Portable

Notice from above code that, the EventSource is openinng a connection to a base64-encoded JSON query object

{
  "v": 3,
  "q": { "find": { "out.h1": "6d02" } }
}
Basically, you're subscribing to that unique base64 encoded string instead of a specific URL.

This content-addressed subscription scheme means multiple bitsocket nodes will always produce the same push notification sets for the same query.

If a bitsocket node goes down, all apps plugged into that node can seamlessly migrate to another bitsocket node, providing application portability and decentralization.


3. Programmable

The query language is not just for simple filtering.

It's powered by Bitquery, a Turing complete Bitcoin query language, which means you can build a programming logic into the query itself to build a custom push API.

For example, you can build your own custom push API for ONLY listening to a certain pattern (memo.cash posts) and then process the raw event to only return the part you need, by adding an additional "processing" step to the query (r.f). Here's an example:

bs.open({
  "v": 3,
  "q": {
    "find": { "out.h1": "6d02" }
  },
  "r": {
    "f": ".[] | .out[] | select(.b0.op? == 106) | .s2"
  }
})
You can also use bitsocket to programmatically trigger ANYTHING.
  1. send mobile push notifications
  2. trigger an event for a 3rd party application
  3. trigger certain action for a hardware device
  4. trigger another bitcoin transaction
  5. send event to another bitcoin app through bitcoin transaction
All you need to do is write an event handler:

bitsocket.on("message", function(event) {
  // Use the 'event' to run whatever logic you want here!
})
What's possible is only bound by your imagination.

4. BitDB Compatible

Bitsocket uses the same query language as BitDB (Bitquery).
You can think of BitDB as a "pull" service, whereas Bitsocket is a "push" service.

You can use both in a single appplication to complement each other