Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Created November 30, 2014 00:24
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 ryandotsmith/77e16986d3703ede8be1 to your computer and use it in GitHub Desktop.
Save ryandotsmith/77e16986d3703ede8be1 to your computer and use it in GitHub Desktop.
Chain jQuery Notifications Websockets Example
<!doctype html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
</head>
<body>
<ul id="thashlist"></ul>
</body>
<script type="text/javascript">
$(function() {
var conn = new WebSocket("wss://ws.chain.com/v2/notifications");
conn.onopen = function (ev) {
var req = {type: "new-transaction", block_chain: "bitcoin"};
conn.send(JSON.stringify(req));
};
conn.onmessage = function (ev) {
var x = JSON.parse(ev.data);
var thash = x['payload']['transaction']['hash'];
$('#thashlist').append('<li>' + thash + '</li>');
};
});
</script>
</html>
@adv0r
Copy link

adv0r commented Jan 22, 2016

is this outdated now? I get a net::ERR_NAME_NOT_RESOLVED . Do you know how to achieve the same result?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment