Websockets for Block.io API giving an error message

0 votes

I just signed up and want to test out the Websockets API to check on an address balance. Following the API docs, I was trying to see if I could get a proof of concept working, but I can't seem to get past the "success" message. Can someone take a look at this code and let me know what I'm doing wrong?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Websocket Test</title>
</head>
<body>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js"></script>
    <script>
        var connection = new WebSocket('wss://n.block.io/:443');
        var message = {
            "type": "account",
            "api_key": "a40c-587d-e9a6-67d3",
            "network": "BTC",
                "type": "address",
                "address": "13qUEUgSZRBqrXUyDghm1JhXMzJyrhA69h"
        };
        connection.onmessage = function(e){
           var server_message = e.data;
           console.log(server_message);
        }
        connection.onopen = function(){
           connection.send(message);
        }
    </script>
</body>
</html>
Sep 10, 2018 in Blockchain by digger
• 27,620 points
31 views

1 answer to this question.

0 votes

Try something like this:

https://jsfiddle.net/bxw3v8c7/

<html>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>

<script>
var btcs = new WebSocket('wss://n.block.io/');

btcs.onopen = function()
    {
    var addrToMonitor = "1SomeBTCAddress";
    btcs.send( JSON.stringify( {'type':'address','network':'BTC', 'address':addrToMonitor} ) );
    };

btcs.onmessage = function(onmsg)
    {
    var response = JSON.parse(onmsg.data);
    console.log(response); //for debugging
    var amount = response.data.amount_received;
    $('#messages').prepend("<p>" + amount + "</p>");
    }

</script>
<body>

</body>
</html>
answered Sep 10, 2018 by slayer
• 29,050 points

Related Questions In Blockchain

+1 vote
1 answer

What is the best way to search for an item in blockchain?

All transactions and records in blockchain are ...READ MORE

answered Apr 20, 2018 in Blockchain by Perry
• 17,010 points
37 views
+1 vote
2 answers
0 votes
1 answer

Web3j Transfer.sendFunds() returns Error “insufficient funds for gas * price + value”

DISCLAIMER. This may not necessarily be an answer to your ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,710 points
304 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 27,620 points
2,094 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
104 views
0 votes
1 answer
0 votes
1 answer