Saturday, November 2, 2024

transactions – Monitor a number of bitcoin addresses

Endpoint

wss://mempool.house/api/v1/ws

Description:

Default push: { motion: ‘need’, knowledge: [‘blocks’, …] } to precise what you need pushed. Obtainable: blocks, mempool-blocks, live-2h-chart, and stats.

Push transactions associated to deal with:

{ ‘track-address’: ‘3PbJ…bF9B’ } to obtain all new transactions containing that tackle as enter or output. Returns an array of transactions. address-transactions for brand spanking new mempool transactions, and block-transactions for brand spanking new block confirmed transactions.

Widespread JS

Code Instance
GitHub Repo

<!DOCTYPE html>
<html>
  <head>
    <script src="https://mempool.house/mempool.js"></script>
    <script>
      const init = async () => {
        
  const { bitcoin: { websocket } } = mempoolJS({
          hostname: 'mempool.house'
        });

  const ws = websocket.initClient({
    choices: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
  });

  ws.addEventListener('message', perform incoming({knowledge}) {
    const res = JSON.parse(knowledge.toString());
    if (res.block) {
      doc.getElementById("result-blocks").textContent = JSON.stringify(res.block, undefined, 2);
    }
    if (res.mempoolInfo) {
      doc.getElementById("result-mempool-info").textContent = JSON.stringify(res.mempoolInfo, undefined, 2);
    }
    if (res.transactions) {
      doc.getElementById("result-transactions").textContent = JSON.stringify(res.transactions, undefined, 2);
    }
    if (res["mempool-blocks"]) {
      doc.getElementById("result-mempool-blocks").textContent = JSON.stringify(res["mempool-blocks"], undefined, 2);
    }
  });
  
      };
      init();
    </script>
  </head>
  <physique>
    <h2>Blocks</h2><pre id="result-blocks">Ready for knowledge</pre><br>
    <h2>Mempool Information</h2><pre id="result-mempool-info">Ready for knowledge</pre><br>
    <h2>Transactions</h2><pre id="result-transactions">Ready for knowledge</pre><br>
    <h2>Mempool Blocks</h2><pre id="result-mempool-blocks">Ready for knowledge</pre><br>
  </physique>
</html>

Or ES Module

Set up Package deal
GitHub RepoNPM Package deal

# npm
npm set up @mempool/mempool.js --save

# yarn
yarn add @mempool/mempool.js

Code Instance

import mempoolJS from "@mempool/mempool.js";

const init = async () => {
  
const { bitcoin: { websocket } } = mempoolJS({
    hostname: 'mempool.house'
  });

const ws = websocket.initServer({
choices: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
});

ws.on("message", perform incoming(knowledge) {
const res = JSON.parse(knowledge.toString());
if (res.block) {
console.log(res.block);
}
if (res.mempoolInfo) {
console.log(res.mempoolInfo);
}
if (res.transactions) {
console.log(res.transactions);
}
if (res["mempool-blocks"]) {
console.log(res["mempool-blocks"]);
}
});
    
};
init();

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles