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
• 26,670 points
159 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,270 points

Related Questions In Blockchain

0 votes
1 answer

My account is already an administrator but its giving the an error on denial of permission

Hi, @There, You can try this in your ...READ MORE

answered Jun 17 in Blockchain by Gitika
• 33,450 points
91 views
+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,090 points
180 views
+1 vote
2 answers
+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
• 26,670 points
16,036 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,090 points
143 views
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,810 points
349 views
0 votes
1 answer
0 votes
1 answer