Skip to main content
Glama

get_difficulty_adjustment

Calculate Bitcoin's difficulty adjustment progress, including blocks in epoch, remaining blocks, estimated time, and projected adjustment.

Instructions

Calculate difficulty adjustment progress: blocks into epoch, blocks remaining, estimated time, and projected adjustment.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_difficulty_adjustment` tool calculates the progress of the current Bitcoin mining difficulty epoch, including blocks remaining and projected adjustment percentage.
    def get_difficulty_adjustment() -> str:
        """Calculate difficulty adjustment progress: blocks into epoch, blocks remaining, estimated time, and projected adjustment."""
        try:
            info = get_rpc().getblockchaininfo()
            height = info["blocks"]
            blocks_into_epoch = height % 2016
            blocks_remaining = 2016 - blocks_into_epoch
            epoch_start_height = height - blocks_into_epoch
            epoch_start_hash = get_rpc().getblockhash(epoch_start_height)
            epoch_start_header = get_rpc().getblockheader(epoch_start_hash)
            current_hash = get_rpc().getblockhash(height)
            current_header = get_rpc().getblockheader(current_hash)
            elapsed_secs = current_header["time"] - epoch_start_header["time"]
            expected_secs = blocks_into_epoch * 600
            if blocks_into_epoch > 0:
                secs_per_block = elapsed_secs / blocks_into_epoch
                est_remaining_secs = blocks_remaining * secs_per_block
                est_adjustment_pct = ((expected_secs / elapsed_secs) - 1) * 100 if elapsed_secs > 0 else 0
            else:
                secs_per_block = 600
                est_remaining_secs = blocks_remaining * 600
                est_adjustment_pct = 0
        except Exception as e:
            return json.dumps({"error": str(e)})
        return json.dumps({
            "current_height": height,
            "epoch_start_height": epoch_start_height,
            "blocks_into_epoch": blocks_into_epoch,
            "blocks_remaining": blocks_remaining,
            "elapsed_seconds": elapsed_secs,
            "expected_seconds": expected_secs,
            "avg_block_time_seconds": round(secs_per_block, 1),
            "est_remaining_seconds": round(est_remaining_secs),
            "est_remaining_hours": round(est_remaining_secs / 3600, 1),
            "est_adjustment_pct": round(est_adjustment_pct, 2),
            "difficulty": info["difficulty"],
        })

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Bortlesboat/bitcoin-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server