Bitcoin Forum
December 15, 2024, 07:50:37 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Is there a way to retrieve bitcoin statistics, such as Difficulty and Hashrate  (Read 168 times)
DrakonX (OP)
Jr. Member
*
Offline Offline

Activity: 99
Merit: 4


View Profile
September 09, 2021, 08:12:22 PM
Merited by NotATether (2)
 #1

Is there a way to retrieve bitcoin statistics, such as Difficulty and Hashrate freqently (especially with JavaScript)? How?
bitmover
Legendary
*
Offline Offline

Activity: 2520
Merit: 6374


Wheel of Whales 🐳


View Profile WWW
September 09, 2021, 08:34:14 PM
Merited by pooya87 (2), Pmalek (2), BlackHatCoiner (2), BitMaxz (1), ABCbits (1), Coin-1 (1), hosseinimr93 (1), NotATether (1)
 #2

Is there a way to retrieve bitcoin statistics, such as Difficulty and Hashrate freqently (especially with JavaScript)? How?

Yes, you can get this data using blockchair api

You can read the documentation here:
https://blockchair.com/api/docs#link_M1

And the api you need is this one:
https://api.blockchair.com/bitcoin/stats

This is the return. It has  hashrate_24h and difficulty values.

Code:
{"data":{"blocks":699810,"transactions":669216274,"outputs":1822960945,"circulation":1881128354497096,"blocks_24h":139,"transactions_24h":263592,"difficulty":18415156832118,"volume_24h":382466097248610,"mempool_transactions":15894,"mempool_size":9213750,"mempool_tps":3.5833333333333335,"mempool_total_fee_usd":12094.621,"best_block_height":699809,"best_block_hash":"0000000000000000000bbbee45774498ad2ee340c5c92bdfa9aee202113ed159","best_block_time":"2021-09-09 20:22:34","blockchain_size":363580998494,"average_transaction_fee_24h":5286,"inflation_24h":86875000000,"median_transaction_fee_24h":1407,"cdd_24h":13879282.242647348,"mempool_outputs":88861,"largest_transaction_24h":{"hash":"358256922857e1fd9ac1fd212d8e08c0e7f28028d2485c13903fecaaec8a5cc1","value_usd":1489689216},"nodes":8209,"hashrate_24h":"127363118107339408072","inflation_usd_24h":40514156.25,"average_transaction_fee_usd_24h":2.4654470845055996,"median_transaction_fee_usd_24h":0.6561544500000001,"market_price_usd":46635,"market_price_btc":1,"market_price_usd_change_24h_percentage":1.06546,"market_cap_usd":879704699184,"market_dominance_percentage":39.76,"next_retarget_time_estimate":"2021-09-22 10:18:56","next_difficulty_estimate":17103153766662,"countdowns":[],"suggested_transaction_fee_per_byte_sat":5,"hodling_addresses":38792149},"context":{"code":200,"source":"A","state":699809,"market_price_usd":46635,"cache":{"live":false,"duration":"Ignore","since":"2021-09-09 20:32:47","until":"2021-09-09 20:33:58","time":4.0531158447265625e-6},"api":{"version":"2.0.88","last_major_update":"2021-07-19 00:00:00","next_major_update":null,"documentation":"https:\/\/blockchair.com\/api\/docs","notice":":)"},"server":"BTC0","time":1.090975046157837,"render_time":0.004091978073120117,"full_time":0.004096031188964844,"request_cost":1}}

You can make the API call easily using javascript, such as fetch

Code:
fetch('https://api.blockchair.com/bitcoin/stats')
  .then(response => response.json())
  .then(data => console.log(data));

███████████▄
████████▄▄██
█████████▀█
███████████▄███████▄
█████▄█▄██████████████
████▄█▀▄░█████▄████████
████▄███░████████████▀
████░█████░█████▀▄▄▄▄▄
█████░█
██░█████████▀▀
░▄█▀
███░░▀▀▀██████
▀███████▄█▀▀▀██████▀
░░████▄▀░▀▀▀▀████▀
 

█████████████████████████
████████████▀░░░▀▀▀▀█████
█████████▀▀▀█▄░░░░░░░████
████▀▀░░░░░░░█▄░▄░░░▐████
████▌░░░░▄░░░▐████░░▐███
█████░░░▄██▄░░██▀░░░█████
█████▌░░▀██▀░░▐▌░░░▐█████
██████░░░░▀░░░░█░░░▐█████
██████▌░░░░░░░░▐█▄▄██████
███████▄░░▄▄▄████████████
█████████████████████████

█████████████████████████
████████▀▀░░░░░▀▀████████
██████░░▄██▄░▄██▄░░██████
█████░░████▀░▀████░░█████
████░░░░▀▀░░░░░▀▀░░░░████
████░░▄██░░░░░░░██▄░░████
████░░████░░░░░████░░████
█████░░▀▀░▄███▄░▀▀░░████
██████░░░░▀███▀░░░░██████
████████▄▄░░░░░▄▄████████
█████████████████████████
.
...SOL.....USDT...
...FAST PAYOUTS...
...BTC...
...TON...
odolvlobo
Legendary
*
Offline Offline

Activity: 4522
Merit: 3427



View Profile
September 10, 2021, 06:39:02 PM
 #3

Is there a way to retrieve bitcoin statistics, such as Difficulty and Hashrate freqently (especially with JavaScript)? How?

Note that network hash rate is a computation based on block timestamps and there is no way to get the true value because blocks are produced at random intervals and the timestamps are not accurate.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
DrakonX (OP)
Jr. Member
*
Offline Offline

Activity: 99
Merit: 4


View Profile
September 10, 2021, 11:04:52 PM
 #4

Thank you, bitmover.

@adolvlobo: I just want to get the same info I can retrieve from the Bitcoin network by typing the command within the Bitcoin Core CLI without using it.
Pmalek
Legendary
*
Offline Offline

Activity: 2982
Merit: 7642


Playgram - The Telegram Casino


View Profile
September 11, 2021, 08:33:57 AM
 #5

I have never looked into it, but I know that Mempool.space has a dedicated API service for Bitcoin. You can find it here > https://mempool.space/api.
Check and see if the features you are interested in can be found among the different tabs at the top.

▄▄███████▄▄███████
▄███████████████▄▄▄▄▄
▄████████████████████▀░
▄█████████████████████▄░
▄█████████▀▀████████████▄
██████████████▀▀█████████
████████████████████████
██████████████▄▄█████████
▀█████████▄▄████████████▀
▀█████████████████████▀░
▀████████████████████▄░
▀███████████████▀▀▀▀▀
▀▀███████▀▀███████

▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
 
Playgram.io
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀

▄▄▄░░
▀▄







▄▀
▀▀▀░░
▄▄▄███████▄▄▄
▄▄███████████████▄▄
▄███████████████████▄
▄██████████████▀▀█████▄
▄██████████▀▀█████▐████▄
██████▀▀████▄▄▀▀█████████
████▄▄███▄██▀█████▐██████
█████████▀██████████████
▀███████▌▐██████▐██████▀
▀███████▄▄███▄████████▀
▀███████████████████▀
▀▀███████████████▀▀
▀▀▀███████▀▀▀
██████▄▄███████▄▄████████
███▄███████████████▄░░▀█▀
███████████░█████████░░
░█████▀██▄▄░▄▄██▀█████░
█████▄░▄███▄███▄░▄█████
███████████████████████
███████████████████████
██░▄▄▄░██░▄▄▄░██░▄▄▄░██
██░░░░██░░░░██░░░░████
██░░░░██░░░░██░░░░████
██▄▄▄▄▄██▄▄▄▄▄██▄▄▄▄▄████
███████████████████████
███████████████████████
 
PLAY NOW

on Telegram
[/
bitmover
Legendary
*
Offline Offline

Activity: 2520
Merit: 6374


Wheel of Whales 🐳


View Profile WWW
September 11, 2021, 11:50:45 AM
Merited by Pmalek (2)
 #6

I have never looked into it, but I know that Mempool.space has a dedicated API service for Bitcoin. You can find it here > https://mempool.space/api.
Check and see if the features you are interested in can be found among the different tabs at the top.

Unfortunately their API doesn't offer difficulty/hashrate on specific time, but only difficulty adjustment.

Yes, mempool.space API won't work for what OP need.

I found another API which will also provide the data he requested. Sochain API.

You can call it here:
https://chain.so/api/v2/get_info/BTC

and the response:
Code:
{
  "status": "success",
  "data": {
    "name": "Bitcoin",
    "acronym": "BTC",
    "network": "BTC",
    "symbol_htmlcode": "฿",
    "url": "https://bitcoin.org",
    "mining_difficulty": "18415156832118.24",
    "unconfirmed_txs": 2350,
    "blocks": 700041,
    "price": "45633.63000000",
    "price_base": "USD",
    "price_update_time": 1631360991,
    "hashrate": "130102593297717500000.0"
  }
}

He needs mining_difficulty and hashrate



Comparing both API (requested both now at time of writing):

Sochain
"mining_difficulty": "18415156832118.24",
"hashrate": "130102593297717500000.0"

Blockchair:
"difficulty":18415156832118,
"hashrate_24h":"128188810931374023359"

Difficult matches, while hashrate has a close value, but doesn't match.

███████████▄
████████▄▄██
█████████▀█
███████████▄███████▄
█████▄█▄██████████████
████▄█▀▄░█████▄████████
████▄███░████████████▀
████░█████░█████▀▄▄▄▄▄
█████░█
██░█████████▀▀
░▄█▀
███░░▀▀▀██████
▀███████▄█▀▀▀██████▀
░░████▄▀░▀▀▀▀████▀
 

█████████████████████████
████████████▀░░░▀▀▀▀█████
█████████▀▀▀█▄░░░░░░░████
████▀▀░░░░░░░█▄░▄░░░▐████
████▌░░░░▄░░░▐████░░▐███
█████░░░▄██▄░░██▀░░░█████
█████▌░░▀██▀░░▐▌░░░▐█████
██████░░░░▀░░░░█░░░▐█████
██████▌░░░░░░░░▐█▄▄██████
███████▄░░▄▄▄████████████
█████████████████████████

█████████████████████████
████████▀▀░░░░░▀▀████████
██████░░▄██▄░▄██▄░░██████
█████░░████▀░▀████░░█████
████░░░░▀▀░░░░░▀▀░░░░████
████░░▄██░░░░░░░██▄░░████
████░░████░░░░░████░░████
█████░░▀▀░▄███▄░▀▀░░████
██████░░░░▀███▀░░░░██████
████████▄▄░░░░░▄▄████████
█████████████████████████
.
...SOL.....USDT...
...FAST PAYOUTS...
...BTC...
...TON...
ranochigo
Legendary
*
Offline Offline

Activity: 3052
Merit: 4444


Crypto Swap Exchange


View Profile
September 11, 2021, 03:20:40 PM
Merited by bitmover (2)
 #7

I just want to get the same info I can retrieve from the Bitcoin network by typing the command within the Bitcoin Core CLI without using it.
It is actually quite easy to do so. The difficulty and the target are both stored within the block headers, it will be sufficient to just call the block headers at each difficulty epoch to get the difficulty for that period. It is pointless to get the hashrate, because any estimation based on timestamps within a short period of time is often quite inaccurate. You can determine it based on the block intervals or use the difficulty as a metric.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
MineSweep
Newbie
*
Offline Offline

Activity: 17
Merit: 7


View Profile
September 11, 2021, 08:39:00 PM
 #8

block difficulty should be adjusted every two weeks and hashrate depends on the miners who can be found hashing in https://ycharts.com/indicators/bitcoin_network_hash_rate
MineSweep
Newbie
*
Offline Offline

Activity: 17
Merit: 7


View Profile
September 11, 2021, 08:50:27 PM
 #9

I just want to get the same info I can retrieve from the Bitcoin network by typing the command within the Bitcoin Core CLI without using it.
It is actually quite easy to do so. The difficulty and the target are both stored within the block headers, it will be sufficient to just call the block headers at each difficulty epoch to get the difficulty for that period. It is pointless to get the hashrate, because any estimation based on timestamps within a short period of time is often quite inaccurate. You can determine it based on the block intervals or use the difficulty as a metric.

Block intervals coinside with the nonce interation achieved in each epoch of bitcoin. In the bitcoin network an epoch is defined as a block interval where production exists once a target hash is SHA-256'd to a low enough byte.
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!