Skip to main content
Glama

search_blockchain

Search Bitcoin blockchain data by automatically detecting transaction IDs, block hashes, block heights, or addresses to retrieve relevant information.

Instructions

Smart search: auto-detects if query is a txid, block hash, block height, or address and returns the right data.

Args: query: A txid (64 hex), block hash (64 hex starting with 0000), block height (number), or Bitcoin address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool "search_blockchain" detects if a query is a block height, txid, block hash, or address and performs the appropriate lookup.
    def search_blockchain(query: str) -> str:
        """Smart search: auto-detects if query is a txid, block hash, block height, or address and returns the right data.
    
        Args:
            query: A txid (64 hex), block hash (64 hex starting with 0000), block height (number), or Bitcoin address
        """
        query = query.strip()
        # Block height (pure digits)
        if query.isdigit():
            try:
                analysis = _analyze_block(get_rpc(), query)
                return analysis.model_dump_json()
            except Exception as e:
                return json.dumps({"error": f"Block lookup failed: {e}"})
        # 64 hex chars — block hash or txid
        if re.fullmatch(r"[0-9a-fA-F]{64}", query):
            if query.startswith("0000"):
                try:
                    analysis = _analyze_block(get_rpc(), query)
                    return analysis.model_dump_json()
                except Exception:
                    pass  # fall through to txid
            try:
                analysis = _analyze_transaction(get_rpc(), query)
                return analysis.model_dump_json()
            except Exception as e:
                return json.dumps({"error": f"Transaction lookup failed: {e}"})
        # Address validation
        try:
            result = get_rpc().validateaddress(query)
            if result.get("isvalid"):
                return json.dumps(result)
        except Exception:
            pass
        return json.dumps({"error": f"Could not identify query: {query!r}. Provide a txid, block hash, block height, or address."})

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