Skip to content

Instantly share code, notes, and snippets.

@orweinberger
Created June 9, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orweinberger/7fca506fe34b8ed9c510 to your computer and use it in GitHub Desktop.
Save orweinberger/7fca506fe34b8ed9c510 to your computer and use it in GitHub Desktop.
Bitcoin socket
<html>
<head>
<script>
var socket = new WebSocket("wss://ws.blockchain.info/inv");
socket.onopen = function (event) {
console.log('connected');
socket.send(JSON.stringify({"op":"unconfirmed_sub"}));
};
socket.onmessage = function (event) {
var sum = 0;
var e = JSON.parse(event.data);
var ins = e.x.inputs.length;
var outs = e.x.out.length;
e.x.out.forEach(function(d) {
sum += d.value;
})
var doc = {
ip: e.x.relayed_by,
sum: sum,
inputs: ins,
outputs: outs,
hash: e.x.hash
}
console.log(doc);
}
</script>
</head>
<body>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment