0

I would like to know if I could monitor new transactions on several addresses that I do not have access to personally and see if the transactions were validated by the network with an API, and if possible to use WebSockets which is very interesting compared to REST APIs.

I have seen the API offer of blockcypher and blockchain.com that meets my request but I wanted to know if there was simpler.

Thanks for your future answers

2 Answers 2

0

Thanks for your answer.

First of all I would like to apologize because I misspoke, I manage an exchange platform on a web application. There was an API that generated and verified the transactions but it became down, therefore unusable and the transactions were all passed in manual.

A trusted person took care of generating public addresses but I don't have access to private keys.

I thought that using a node on the Bitcoin protocol to track transactions using the RPC API might be a good idea, as I would have no limit to the use of the protocol, unlike using a third party.

Now it's up to me to see the maintenance costs involved, as it's better to use a remote server for performance reasons and to synchronize completely to the network, as the blockchain is constantly increasing in size.

0

Endpoint

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

Description:

Default push: { action: 'want', data: ['blocks', ...] } to express what you want pushed. Available: blocks, mempool-blocks, live-2h-chart, and stats.

Push transactions related to address:

{ 'track-address': '3PbJ...bF9B' } to receive all new transactions containing that address as input or output. Returns an array of transactions. address-transactions for new mempool transactions, and block-transactions for new block confirmed transactions.

Common JS

Code Example GitHub Repo

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

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

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

Or ES Module

Install Package GitHub RepoNPM Package

# npm
npm install @mempool/mempool.js --save

# yarn
yarn add @mempool/mempool.js

Code Example

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

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

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

ws.on("message", function incoming(data) {
const res = JSON.parse(data.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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.