This is a plugin for OpenAgents that gives you the latest statistics about the Bitcoin network, its mempool and the Lightning Network.
It is inspired by Clark Moody's Bitcoin Dashboard and the TimechainCalendar.
The project uses the Extism Framework, in particular its Go PDK, and the REST APIs of mempool.space, bitnodes.io and coincap.io.
Make sure you have both Go and TinyGo.
Clone this repo:
git clone https://github.com/sfr0xyz/openagents-bitcoin-stats.git
Build the plugin with TinyGo:
tinygo build -o btcstats.wasm -target wasi .
Ensure that you have installed the Extism CLI and downloaded the btcstats.wasm
file.
You can call the plugin with the Extism CLI:
extism call btcstats.wasm run --input '<YOUR INPUT>' --wasi --allow-host '*'
Replace <YOUR INPUT>
with a list of statistics you are interested in.
Available statistics (see detailed descriptions below)
market
: Bitcoin market data such as current price and market caplatestBlock
: Information about the latest block, such as size and total rewardmining
: Mining data such as current hashrate and difficulty, and difficulty adjustmentfees
: Recommended feerates based on the current mempoolmempool
: Mempool statistics such as number of unconfirmed transactions and pending feeslightning
: Lightning Network statistics such as total capacity and number of channelsnodes
: Bitcoin node statistics such as total number of nodes
You can include more than one of the above at once.
If you leave the field empty (''
), or include none of the above, all stats will be requested.
With the prefix -
, e.g. -nodes
, you can exclude stats, i.e. "I want all stats except nodes
".
Note: If you request the
nodes
statistic, it will take a while, a few seconds, for the result to be displayed.
Note: The resulting JSON is prettified here for better readability.
Get all stats:
$ extism call btcstats.wasm run --input '' --wasi --allow-host '*'
{
"fees": {
"fastest": 9,
"halfHour": 9,
"hour": 9,
"economy": 6,
"minimum": 3
},
"latestBlock": {
"height": 845325,
"timestamp": "Mon, 27 May 2024 01:34:54 UTC",
"transactions": 5692,
"size": 1.55,
"totalReward": 3.272,
"totalFees": 0.147,
"medianFeeRate": 8.1,
"miner": "MARA Pool"
},
"lightning": {
"totalNodes": 12836,
"torNodes": 8930,
"clearnetNodes": 1700,
"clearnetTorNodes": 1360,
"unannouncedNodes": 846,
"channels": 50872,
"totalCapacity": 4980.822,
"averageChannelCapacity": 0.098,
"medianChannelCapacity": 0.02
},
"market": {
"supply": 19699693,
"supplyPercent": 93.81,
"price": 69020.61,
"priceChange24hPercent": -0.32,
"moscowTime": 1448,
"marketCap": 1359684729700.71
},
"mempool": {
"unconfirmedTXs": 170669,
"vSize": 180.66,
"pendingFees": 5.257,
"blocksToClear": 181
},
"mining": {
"hashrate": 677612693053317300000,
"difficulty": 84381461788831.34,
"retargetDifficultyChangePercent": 13.39,
"retargetRemainingBlocks": 1395,
"retargetEstimatedDate": "Tue, 04 Jun 2024 15:07:02 UTC"
},
"nodes": {
"totalNodes": 18037,
"torNodes": 10942,
"torNodesPercent": 60.66
}
}
Get all stats except nodes
:
$ extism call btcstats.wasm run --input '-nodes' --wasi --allow-host '*'
{
"fees": {
"fastest": 9,
"halfHour": 9,
"hour": 9,
"economy": 6,
"minimum": 3
},
"latestBlock": {
"height": 845325,
"timestamp": "Mon, 27 May 2024 01:34:54 UTC",
"transactions": 5692,
"size": 1.55,
"totalReward": 3.272,
"totalFees": 0.147,
"medianFeeRate": 8.1,
"miner": "MARA Pool"
},
"lightning": {
"totalNodes": 12836,
"torNodes": 8930,
"clearnetNodes": 1700,
"clearnetTorNodes": 1360,
"unannouncedNodes": 846,
"channels": 50872,
"totalCapacity": 4980.822,
"averageChannelCapacity": 0.098,
"medianChannelCapacity": 0.02
},
"market": {
"supply": 19699693,
"supplyPercent": 93.81,
"price": 69020.61,
"priceChange24hPercent": -0.32,
"moscowTime": 1448,
"marketCap": 1359684729700.71
},
"mempool": {
"unconfirmedTXs": 170669,
"vSize": 180.66,
"pendingFees": 5.257,
"blocksToClear": 181
},
"mining": {
"hashrate": 677612693053317300000,
"difficulty": 84381461788831.34,
"retargetDifficultyChangePercent": 13.39,
"retargetRemainingBlocks": 1395,
"retargetEstimatedDate": "Tue, 04 Jun 2024 15:07:02 UTC"
}
}
Get latestBlock
and mempool
stats:
$ extism call btcstats.wasm run --input 'latestBlock mempool' --wasi --allow-host '*'
{
"latestBlock": {
"height": 845325,
"timestamp": "Mon, 27 May 2024 01:34:54 UTC",
"transactions": 5692,
"size": 1.55,
"totalReward": 3.272,
"totalFees": 0.147,
"medianFeeRate": 8.1,
"miner": "MARA Pool"
},
"mempool": {
"unconfirmedTXs": 170669,
"vSize": 180.66,
"pendingFees": 5.257,
"blocksToClear": 181
}
}
market
: Bitcoin market dataprice
: current US Dollar price for 1 bitcoinpriceChange24hPercent
: US Dollar price change withng the last 24 hour in percentmoscowTime
: current Moscow time, i.e. sats/USDsupply
: current amount of available bitcoinsupplyPercent
: percentage of current supply from the maximum of 21'000'000 bitcoinmarketCap
: current market capitalisation (price x supply)
latestBlock
: Information about the latest blockheight
: block heighttimestamp
: the block's timestamp (format: ddd, DD MMM YYYY HH:mm:ssZ)transactions
: number of transactions in the blocksize
: block size in MBreward
: total block reward, i.e. subsidy + total fees, in BTCtotalFees
: total amount of fees from the transactions in BTCmedianFeeRate
: median fee rate paid by the included transactions in sats/vBminer
: name of the miner's mining pool
mining
: Mining datahashrate
: current hashratedifficulty
: current difficultyretargetDifficultyChangePercent
: difficulty change at the next difficulty adjustment in percentretargetRemainingBlocks
: remaining blocks until difficulty adjustmentretargetEstimatedDate
: estimated date of the difficulty adjustment (format: ddd, DD MMM YYYY HH:mm:ssZ)
fees
: Recommended feerates based on the current mempoolfastest
: fee rate to get into the next block in sats/vBhalfHour
: fee rate to get into a block within the next 30min in sats/vBhour
: fee rate to get into a block within the next 1 hour in sats/vBeconomy
: no priority fee rate on sats/vBminimum
: minimum fee rate to not be purged from the mempool
mempool
: Mempool statisticsunconfirmedTXs
: current number of transactions in the mempoolvSize
: virtual size of all transaction in the mempoolpendingFees
: total amount of fees from the transaction in the mempool in BTCblocksToClear
: estimated number of blocks until all transaction in the mempool are included in a block
lightning
: Lightning Network statisticstotalNodes
: total number of Lightning nodestorNodes
: number Lightning nodes running behind TORclearnetNodes
: number of Lightning nodes running on clearnetclearnetTorNodes
: number of Lightning nodes that run on clearnet and behind TORunannouncedNodes
: number of unannounced Lightning nodeschannels
: number of announced Lightning channelstotalCapacity
: total amount of (visible) BTC in Lightning channelsaverageChannelCapacity
: average amount of BTC per channelmedianChannelCapacity
: median amount of BTC per channel
nodes
: Bitcoin node statisticstotalNodes
: total number of Bitcoin nodestorNodes
: number of Bitcoin nodes behind TORtorNodesPercent
: percentage of nodes behind TOR from the total number