Chain jQuery Notifications Websockets Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this outdated now? I get a
net::ERR_NAME_NOT_RESOLVED
. Do you know how to achieve the same result?