I’ve written this easy PHP code with a proof for every comma
PHP code
<?php
$lastBlockEnd = $this->MyRPC->BitcoinCoreCommand('getblockcount' , []);
// https://bitcoin.org/en/developer-reference#getblockcount
for ($i = 0; $i <= $lastBlockEnd; $i++){
$blockHash = $this->MyRPC->BitcoinCoreCommand('getblockhash' , [$i]);
//https://bitcoin.org/en/developer-reference#getblockhash
$blockData = $this->MyRPC->BitcoinCoreCommand('getdata' , [$blockHash]);
//https://bitcoin.org/en/developer-reference#getblock
$block[$i]['time'] = $blockData['time'];
$block[$i]['hash'] = $blockHash;
}
print_r($block);
Code Clarification
- We’re getting complete out there blocks quantity, say its 65443
- we are going to begin looping from block quantity 0 to 65443
Be aware: It’s best to ship “batch request” as a substitute of calling every block individually
– we’re getting block hash, then we’re callinggetdata
and passing that block hash.
Now we have got the next response:
{
"hash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
"confirmations": 447014,
"strippedsize": 215,
"dimension": 215,
"weight": 860,
"peak": 1,
"model": 1,
"versionHex": "00000001",
"merkleroot": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
"tx": [
"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"
],
"time": 1231469665,
"mediantime": 1231469665,
"nonce": 2573394689,
"bits": "1d00ffff",
"problem": 1,
"chainwork": "0000000000000000000000000000000000000000000000000000000200020002",
"previousblockhash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"nextblockhash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd"
}
Lastly, We’re storing time
and block hash in an array and printing it.