Bitcoin Forum
May 06, 2024, 02:02:34 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Question to Bitcoin expert in getJSON, Javascript and Blockchain API  (Read 824 times)
darius2020 (OP)
Member
**
Offline Offline

Activity: 72
Merit: 10


View Profile
January 28, 2014, 03:44:17 PM
Last edit: January 28, 2014, 04:09:51 PM by darius2020
 #1

Hi,

I am trying to download Bitcoin block headers from Blockchain.info via API
using
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

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

to parse blocks i=1 to 10

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 ?
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!