SDKs overview

Mempool.space provides a real-time visualizer and API for the Bitcoin blockchain, including the mempool, blocks, and the Lightning Network. The project offers a RESTful API that allows developers to programmatically fetch data related to transactions, addresses, blocks, and network statistics Mempool API reference. To streamline development, both official and community-contributed SDKs and libraries are available, abstracting direct HTTP requests and providing language-specific interfaces for easier integration.

These SDKs and libraries are designed to simplify tasks such as:

  • Fetching the current mempool state, including transaction counts and fees.
  • Retrieving details for specific transactions, blocks, or addresses.
  • Monitoring the progress of unconfirmed transactions.
  • Accessing Lightning Network channel and node information.
  • Building custom applications for Bitcoin network analysis or wallet integrations.

While the primary method of interaction is through the Mempool REST API, SDKs provide a layer of abstraction that handles serialization, deserialization, and request management, allowing developers to focus on application logic rather than low-level API interactions. The Mempool.space project maintains a commitment to open-source development, encouraging community contributions to its ecosystem of tools and libraries Mempool.space homepage.

Official SDKs by language

Mempool.space primarily provides a comprehensive REST API, and while directly maintained SDKs are limited to specific functionalities, the project encourages community development. The core interaction model involves direct API calls, but specific utilities are offered or supported by the project. The following table outlines key official or officially endorsed libraries and their status.

Language Package/Repository Description Maturity
JavaScript/TypeScript @mempool/mempool.js Official JavaScript/TypeScript library for interacting with the Mempool API. Provides methods for fetching various types of blockchain data. Stable
Python (No official standalone SDK; direct API interaction recommended) Python developers typically use standard HTTP client libraries (e.g., requests) to interact with the Mempool REST API directly. N/A (API-centric)
Go (No official standalone SDK; direct API interaction recommended) Go developers typically use standard HTTP client libraries (e.g., net/http) to interact with the Mempool REST API directly. N/A (API-centric)

The @mempool/mempool.js library is the most prominent official SDK, offering a streamlined experience for web and Node.js environments. For other languages, direct API integration using standard HTTP clients remains the recommended and most flexible approach, as demonstrated in the Mempool API documentation.

Installation

Installation methods vary depending on the chosen language and whether you're using an official SDK or a community-contributed library. For the official JavaScript/TypeScript library, installation is typically performed via npm or yarn.

JavaScript/TypeScript (@mempool/mempool.js)

To install the official Mempool.js library:

npm install @mempool/mempool.js
# or
yarn add @mempool/mempool.js

This command adds the library to your project's dependencies, making its functions available for use in your JavaScript or TypeScript code.

Other Languages (Direct API interaction)

For languages without a dedicated official SDK, such as Python or Go, you will use their respective package managers to install an HTTP client library. For example, in Python, the requests library is a common choice:

pip install requests

In Go, the standard library's net/http package is usually sufficient and requires no additional installation:

import (
    "net/http"
    // ... other imports ...
)

func main() {
    // Your code here
}

These clients will then be used to construct and send requests to the Mempool REST API endpoints, parsing the JSON responses directly.

Quickstart example

This quickstart demonstrates how to fetch the latest block height using both the official JavaScript SDK and a direct Python API call. These examples connect to the public Mempool.space instance.

JavaScript/TypeScript (using @mempool/mempool.js)

This example initializes the Mempool.js client and fetches the current block height.

import { MempoolClient } from '@mempool/mempool.js';

async function getLatestBlockHeight() {
  try {
    const mempool = new MempoolClient();
    const blockHeight = await mempool.bitcoin.blocks.getBlocksTipHeight();
    console.log('Latest Block Height:', blockHeight);
  } catch (error) {
    console.error('Error fetching block height:', error);
  }
}

getLatestBlockHeight();

Python (direct API call using requests)

This Python example uses the requests library to make an HTTP GET request to the Mempool API and parse the JSON response to get the latest block height.

import requests

def get_latest_block_height_python():
    api_url = "https://mempool.space/api/v1/blocks/tip/height"
    try:
        response = requests.get(api_url)
        response.raise_for_status()  # Raise an exception for HTTP errors
        block_height = response.json()
        print(f"Latest Block Height: {block_height}")
    except requests.exceptions.RequestException as e:
        print(f"Error fetching block height: {e}")

get_latest_block_height_python()

These examples illustrate the basic process of interacting with the Mempool API to retrieve data. Further examples for fetching transaction details, address information, or mempool statistics can be found in the Mempool API documentation.

Community libraries

Given Mempool.space's open-source nature and comprehensive REST API, a variety of community-contributed libraries and wrappers have emerged across different programming languages. These libraries often extend functionality, provide language-idiomatic interfaces, or integrate with specific frameworks. While not officially maintained by the Mempool.space team, they can offer valuable tools for developers.

Examples of common community contributions often include:

  • Rust crates: For developers building high-performance or embedded applications, Rust libraries might offer async interfaces and strong typing for Mempool API interactions.
  • PHP packages: Integrations for web frameworks like Laravel or Symfony, providing convenient ways to fetch Bitcoin data within a PHP application.
  • Ruby gems: Libraries simplifying API calls for Ruby on Rails or other Ruby-based projects.
  • Desktop application wrappers: Tools that integrate Mempool data into specific desktop environments or custom monitoring dashboards.

Developers seeking community-supported options are advised to search language-specific package repositories (e.g., PyPI for Python, crates.io for Rust, npm for JavaScript) and GitHub for projects tagged with "mempool" or "bitcoin explorer." Always review the library's documentation, community activity, and licensing before integrating it into a production environment. For example, a search on GitHub for "mempool api python" can reveal several community projects. Independent authorities like the Mozilla Developer Network provide general guidance on working with HTTP APIs, which is fundamental to using any Mempool library or direct integration.

When choosing a community library, consider factors such as:

  • Active maintenance: Is the library regularly updated to reflect API changes or new features?
  • Documentation quality: Is there clear and comprehensive documentation for usage and examples?
  • Test coverage: Does the project have a robust test suite to ensure reliability?
  • Community support: Is there an active community for questions and issue resolution?
  • Security audits: For critical applications, check if the library has undergone any security reviews.

The Mempool.space official documentation remains the definitive source for the API specification, which is crucial for verifying the correctness and completeness of any third-party library's implementation Mempool REST API documentation.