Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: darius2020 on January 28, 2014, 03:44:17 PM



Title: Question to Bitcoin expert in getJSON, Javascript and Blockchain API
Post by: darius2020 on January 28, 2014, 03:44:17 PM
Hi,

I am trying to download Bitcoin block headers from Blockchain.info via API
using
https://blockchain.info/block-index/100?format=json (https://blockchain.info/block-index/100?format=json)

and getJSON  + Javascript
to parse json file from a remote web server
to get 6 block header input parameters into my Bitcoin miner in plain Javascript (under development)

Tell me how to modify this code to get remote json file and parse data

(just tested this demo on a web server)

Quote
<html>
<head>
<title>the title</title>
   <script type="text/javascript"
   src="/jquery/jquery-1.3.2.min.js"></script>
   <script type="text/javascript" language="javascript">
   $(document).ready(function() {
      $("#driver").click(function(event){
          $.getJSON('https://blockchain.info/block-index/100?format=json', function(jd) {
             $('#stage').html('<p> Hash: ' + jd.hash + '</p>');
             $('#stage').append('<p>Ver: ' + jd.ver+ '</p>');
             $('#stage').append('<p>Time: ' + jd.time+ '</p>');
          });
      });
   });
   </script>
</head>
<body>
   <p>Click on the button to load result.html file:</p>
   <div id="stage" style="background-color:blue;">
          STAGE
   </div>
   <input type="button" id="driver" value="Load Data" />
</body>
</html>

Do I have to loop API call
https://blockchain.info/api/blockchain_api (https://blockchain.info/api/blockchain_api)

http://blockchain.info/rawblock/$block_index (http://blockchain.info/rawblock/$block_index)

to parse blocks i=1 to 10

http://blockchain.info/rawblock/i (http://blockchain.info/rawblock/i)

or API can be modified to download file made of 10 block headers in JSON format in one pass ?

Just testing one another getJSON test to access Blockchain header via API

Quote
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $.getJSON("https://blockchain.info/block-index/100?format=json",function(result){
      $.each(result, function(i, field){
        $("div").append(field + " ");
      });
    });
  });
});
</script>
</head>
<body>

<button>Get JSON data</button>
<div></div>

</body>
</html>

Ok, this Javascript code is run on local web server, accessing file from a remote web server
but exactly the case with Blockchain.info + API

Blockchain.info = remote server
My Javascript getJSON is run locally

previewed a large number of examples, demos and none worked for me.

Any help ?