Mempool Node API
  • Overview
    • Get Your API Credentials
  • Mempool Tools Suite
    • Mempool Configuration API
    • Connect via Webhook
    • Connect via Web Socket
    • Rate Limits
  • Gas Prediction Tools Suite
    • Gas Estimator Platform API
    • Rate Limits
  • Discord
  • Github
Powered by GitBook
On this page
  • Getting Started
  • Setup API Configuration
  • Configure Web Socket
  • Add Whitelist Addresses
  • Add Address to Watch
  • Start Receiving Data via Web Socket
  • Examples in Javascript, Rust, TypeScript, Java, , C++, Python & C#
  1. Mempool Tools Suite

Connect via Web Socket

Connect to Mempool Node's mempool monitoring services with web sockets.

PreviousConnect via WebhookNextRate Limits

Last updated 1 year ago

Good to know: All mempool data are sent as a JSON payload, you must use the following ws address with your API Key appended to connect:

wss://api.mempoolnode.com/ws?apiKey={YOUR-API-KEY}

*Where "{YOUR-API-KEY}" is to be replaced with your API Key.

Getting Started

Setup API Configuration

  1. Create a Mempool Node account, by clicking the "Register" button on the top right of our , and complete the registration form.

  2. Mempool Node will create an API Key named "Mempool Key 1" for your account, that you can configure to use. You can create additional API keys from your by clicking the "+" button at the top right of Mempool Key 1.

Configure Web Socket

Configure a new web socket for your API configuration by toggling the "Webhook/Web Socket" to "Web Socket" and then clicking "â‹®" next to the On/Off toggle on the right, and selecting "Configure". This will open a form, in which you populate your webhook specifics: Whitelist Addresses, Blockchain(Currently Ethereum & Binance Smart Chain are supported) & Watched Addresses. Once completed, click the green "Save" button.

Add Whitelist Addresses

By default there is a field available for you to enter a valid IP or URL address to whitelist, however, to add an additional address to whitelist click the "+" on the right of "Whitelist Addresses" and enter the address you wish to whitelist. Once completed, click the green "Save" button.

Add Address to Watch

By default there is a field available for you to enter an address to watch, however, to add an additional address to watch click the "+" on the right of "Watched Addresses" and enter the address you wish to watch. Once completed, click the green "Save" button.

Ethereum & Binance Smart Chain addresses start with "0x" followed by 40 characters. Any valid ETH or BSC address will be accepted, this also includes external accounts and smart contract addresses.

To stop watching a specific address entered, you can click the trash/bin icon next to the address, and once saved, you'll no longer watch that address. Once completed, click the green "Save" button.

Start Receiving Data via Web Socket

Now that everything is configured, all you have to do is toggle the On/Off switch for the specific Mempool API Key you wish to start receiving data, and your mempool data will begin to fly in. Viola!

Examples in Javascript, Rust, TypeScript, Java, , C++, Python & C#

const WebSocket = require('websocket').client;

const apiKey = "YOUR-API-KEY"; // Replace with your actual API key
const wsUrl = `wss://api.mempoolnode.com/ws?apiKey=${apiKey}`;

const client = new WebSocket();

client.on('connectFailed', (error) => {
    console.error(`Connection error: ${error.toString()}`);
});

client.on('connect', (connection) => {
    console.log('Connected to WebSocket');

    connection.on('error', (error) => {
        console.error(`Connection error: ${error.toString()}`);
    });

    connection.on('close', () => {
        console.log('Connection closed');
    });

    connection.on('message', (message) => {
        if (message.type === 'utf8') {
            console.log(`Received data: ${message.utf8Data}`);
        }
    });
});

client.connect(wsUrl);
import * as WebSocket from 'websocket';

const apiKey = "YOUR-API-KEY"; // Replace with your actual API key
const wsUrl = `wss://api.mempoolnode.com/ws?apiKey=${apiKey}`;

const client = new WebSocket.client();

client.on('connect', (connection) => {
    console.log('Connected to WebSocket');

    connection.on('message', (message) => {
        if (message.type === 'utf8') {
            console.log(`Received data: ${message.utf8Data}`);
        }
    });

    connection.on('close', () => {
        console.log('WebSocket connection closed');
    });
});

client.connect(wsUrl);
use async_tungstenite::tungstenite::protocol::Message;
use futures_util::stream::StreamExt;
use std::error::Error;
use async_tungstenite::tokio::connect_async;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let api_key = "YOUR-API-KEY"; // Replace with your actual API key
    let ws_url = format!("wss://api.mempoolnode.com/ws?apiKey={}", api_key);

    let (ws_stream, _) = connect_async(ws_url).await?;
    let (mut write_stream, mut read_stream) = ws_stream.split();

    while let Some(Ok(msg)) = read_stream.next().await {
        if let Message::Text(data) = msg {
            println!("Received data: {}", data);
        }
    }

    Ok(())
}
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.net.URISyntaxException;

public class WebSocketExample {
    public static void main(String[] args) throws URISyntaxException {
        String apiKey = "YOUR-API-KEY"; // Replace with your actual API key
        String wsUrl = "wss://api.mempoolnode.com/ws?apiKey=" + apiKey;

        WebSocketClient client = new WebSocketClient(new URI(wsUrl)) {
            @Override
            public void onOpen(ServerHandshake serverHandshake) {
                System.out.println("Connected to WebSocket");
            }

            @Override
            public void onMessage(String message) {
                System.out.println("Received data: " + message);
            }

            @Override
            public void onClose(int code, String reason, boolean remote) {
                System.out.println("WebSocket connection closed");
            }

            @Override
            public void onError(Exception e) {
                e.printStackTrace();
            }
        };

        client.connect();
    }
}
import asyncio
import websockets

async def connect_to_websocket():
    api_key = "YOUR-API-KEY"  # Replace with your actual API key
    ws_url = f"wss://api.mempoolnode.com/ws?apiKey={api_key}"

    async with websockets.connect(ws_url) as websocket:
        while True:
            # Receive and process data from the WebSocket server as needed
            data = await websocket.recv()
            print(f"Received data: {data}")

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(connect_to_websocket())TypeScript
using System;
using WebSocketSharp;

class Program
{
    static void Main(string[] args)
    {
        string apiKey = "YOUR-API-KEY"; // Replace with your actual API key
        string wsUrl = $"wss://api.mempoolnode.com/ws?apiKey={apiKey}";

        using (var ws = new WebSocket(wsUrl))
        {
            ws.OnMessage += (sender, e) =>
            {
                if (e.IsText)
                {
                    Console.WriteLine($"Received data: {e.Data}");
                }
            };

            ws.OnError += (sender, e) =>
            {
                Console.WriteLine($"WebSocket error: {e.Message}");
            };

            ws.OnClose += (sender, e) =>
            {
                Console.WriteLine("WebSocket connection closed");
            };

            ws.Connect();
            Console.WriteLine("Connected to WebSocket");

            Console.ReadLine(); // Keep the application running
        }
    }
}
#include <iostream>
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>

typedef websocketpp::client<websocketpp::config::asio_tls_client> client;

int main() {
    std::string apiKey = "YOUR-API-KEY"; // Replace with your actual API key
    std::string wsUrl = "wss://api.mempoolnode.com/ws?apiKey=" + apiKey;

    client c;

    c.init_asio();

    c.set_tls_init_handler([](websocketpp::connection_hdl) {
        return websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv12);
    });

    c.set_message_handler([](websocketpp::connection_hdl hdl, client::message_ptr msg) {
        if (msg->get_opcode() == websocketpp::frame::opcode::text) {
            std::cout << "Received data: " << msg->get_payload() << std::endl;
        }
    });

    websocketpp::lib::error_code ec;
    client::connection_ptr con = c.get_connection(wsUrl, ec);

    if (ec) {
        std::cout << "Error connecting: " << ec.message() << std::endl;
        return 1;
    }

    c.connect(con);

    c.run();

    return 0;
}
Dashboard
Dashboard
Add API Configuration Key
Web Socket Configuration Form for API Mempool Key
Toggle On Web Socket