Bitcoin Stats Plugin for OpenAgents

Sefiro

28. Mai 2024May 28, 2024 · 3 Min. Lesezeit3 min read

GitHub Repository Lightning Address
https://github.com/sfr0xyz/openagents-bitcoin-stats sefiro@getalby.com

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.

Usage#

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 on GitHub):

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.

Examples1#

Note: The resulting JSON is prettified here for better readability.

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
  },
  "mining": {
    "hashrate": 677612693053317300000,
    "difficulty": 84381461788831.34,
    "retargetDifficultyChangePercent": 13.39,
    "retargetRemainingBlocks": 1395,
    "retargetEstimatedDate": "Tue, 04 Jun 2024 15:07:02 UTC"
  }
}

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"
  }
}
  1. more examples in the README on GitHub ↩︎

Written by

Comments

No comments yet. Start the conversation.