2

Is there an API that makes streams transactions as they're confirmed? Everything I can find seems to just be putting out unconfirmed transactions in realtime, rather than waiting for confirmation.

To clarify, I'm looking to stream all transactions, not just one wallet.

1 Answer 1

1

You can't really "stream" them. Transactions get confirmed once included in a block. So for 10 minutes you would have nothing and then all of a sudden there would be a 1,000+ transactions with a confirmation. If that's what you're looking for you can just use something like https://blockchain.info/block-index/$block_index?format=json and replace $block_index with the latest block. The json will respond with all transaction id's in an array that were included under "tx":

https://blockchain.info/api/blockchain_api

EDIT:
Blockchain.info has all the info you need. First get the current block height which you can get from https://blockchain.info/stats?format=json

$bcinfo = json_decode(file_get_contents("https://blockchain.info/stats?format=json"), true);
$latestblock = $bcinfo["n_blocks_total"];

Then plug the current block into https://blockchain.info/block-height/$latestblock?format=json

$getblock = json_decode(file_get_contents("https://blockchain.info/block-height/".$latestblock."?format=json"), true);    

Then just count the amount for each array and run a for loop to grab each input(from address) and each output(receiver) along with the time.

Here's one I did quickly in PHP: http://phpfiddle.org/lite/code/k16m-r8fh

<?php
$bcinfo = json_decode(file_get_contents("https://blockchain.info/stats?format=json"), true);
$latestblock = $bcinfo["n_blocks_total"];
$getblock = json_decode(file_get_contents("https://blockchain.info/block-height/".$latestblock."?format=json"), true);
$counttxs = count($getblock["blocks"][0]["tx"]);
for($i=0;$i<$counttxs;$i++){
    //tx time
    $timetx = $getblock["blocks"][0]["tx"][$i]["time"];
    $date = date('Y-m-d, H:i:s', $timetx);
    echo $date."<br>";
    //count inputs
    $countinputs = count($getblock["blocks"][0]["tx"][$i]["inputs"]);
    for($ii=0;$ii<$countinputs;$ii++){
        //get input address
        $addr = $getblock["blocks"][0]["tx"][$i]["inputs"][$ii]["prev_out"]["addr"];
        echo $addr ? "INPUT: ".$addr."<br>" : "";
    }
    //count outputs
    $countouts = count($getblock["blocks"][0]["tx"][$i]["out"]);
    for($iii=0;$iii<$countouts;$iii++){
        //get output address
        $outaddr = $getblock["blocks"][0]["tx"][$i]["out"][$iii]["addr"];
        echo $outaddr ? "OUTPUT: ".$outaddr."<br>" : "";
    }
    echo "<br><br>";
}

?>
2
  • Is there any API out there that makes it easy to get at the send/receive addresses and original date/time a transaction appeared for transactions that have been verified in the blockchain?
    – geofurb
    May 29, 2016 at 0:52
  • Yes you can just use blockchain.info they have all the info. I edited my answer to include some code examples.
    – m1xolyd1an
    May 29, 2016 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.