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_M1And the api you need is this one:
https://api.blockchair.com/bitcoin/statsThis is the return. It has
hashrate_24h and
difficulty values.
{"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 fetch('https://api.blockchair.com/bitcoin/stats')
.then(response => response.json())
.then(data => console.log(data));