Giter VIP home page Giter VIP logo

Comments (5)

wiz avatar wiz commented on July 20, 2024

@knorrium @hunicus can you please look into fixing this as well as the API docs? seems it doesn't work and the API docs are wrong too

from mempool.js.

justficks avatar justficks commented on July 20, 2024

Working example

import * as WebSocket from 'ws';

const serverWS = (): WebSocket => {
  const ws = new WebSocket('wss://mempool.space/testnet/api/v1/ws');
  const interval = setInterval(function ping() {
    ws.ping();
  }, 30000);

  ws.on('open', function open() {
    console.log('ws opened');
    ws.send(
      JSON.stringify({ 'track-address': 'mq9Kmu6AGUmbgAJ73SdkERg59uXFnNeCX2' }),
    );
  });

  ws.on('close', async function close() {
    console.log('ws closed');
    clearInterval(interval);
    ws.terminate();
    await sleep(60000);
    serverWS();
  });

  return ws;
};

const sleep = (ms: number) => {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
};

export { serverWS };

And after

const ws = serverWS();
ws.on('message', function incoming(data) {
  const res = JSON.parse(data.toString()) // <- your tx data here
  console.log(JSON.stringify(res, null, 3))
});

But it doesn't work as expected. Incoming only one transaction notification like:

{
   "address-transactions": [
      {
         "vsize": 143,
         "feePerVsize": 1.0052356020942408,
         "effectiveFeePerVsize": 1.0052356020942408,
         "txid": "57b26a3b5c10f9652d8144bc8431daf45fb2cc19f5d2af488e0c611bb57eb2ed",
         "version": 2,
         "locktime": 2281541,
         "vin": [
            {
               "txid": "721a9c0d53152aaae66a234fb7074e49ae5fcbd90ca879af93abed463d84ecbf",
               "vout": 0,
               "prevout": {
                  "scriptpubkey": "0014250a3f51ebfd2608206d34034d1a1629bcad66a8",
                  "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 250a3f51ebfd2608206d34034d1a1629bcad66a8",
                  "scriptpubkey_type": "v0_p2wpkh",
                  "scriptpubkey_address": "tb1qy59r750tl5nqsgrdxsp56xsk9x726e4gdqsk86",
                  "value": 139284092
               },
               "scriptsig": "",
               "scriptsig_asm": "",
               "witness": [
                  "304402203b68c1f7bfecaba2c213ec631cfd58ed8edb85f1838d14d23a366a9335e8f2b602207651bfd32c93200ca192954cf15a2b784d73b166731e8c7bdc3330c246c417a301",
                  "02e30949984d16c3b9d87d10ad2bba140e31339f37afdfa59515e905e8f553d431"
               ],
               "is_coinbase": false,
               "sequence": 4294967294
            }
         ],
         "vout": [
            {
               "scriptpubkey": "001460651d9d488fd59674d650b2269fe09953b2d4c8",
               "scriptpubkey_asm": "OP_0 OP_PUSHBYTES_20 60651d9d488fd59674d650b2269fe09953b2d4c8",
               "scriptpubkey_type": "v0_p2wpkh",
               "scriptpubkey_address": "tb1qvpj3m82g3l2evaxk2zezd8lqn9fm94xgq2g939",
               "value": 139253948
            },
            {
               "scriptpubkey": "76a914699a098fbfbcc2b5e03fb7edb2ce8b6e166e3f7c88ac",
               "scriptpubkey_asm": "OP_DUP OP_HASH160 OP_PUSHBYTES_20 699a098fbfbcc2b5e03fb7edb2ce8b6e166e3f7c OP_EQUALVERIFY OP_CHECKSIG",
               "scriptpubkey_type": "p2pkh",
               "scriptpubkey_address": "mq9Kmu6AGUmbgAJ73SdkERg59uXFnNeCX2",
               "value": 30000
            }
         ],
         "size": 225,
         "weight": 573,
         "fee": 144,
         "status": {
            "confirmed": false
         },
         "firstSeen": 1655887723,
         "bestDescendant": null,
         "ancestors": [
            {
               "txid": "721a9c0d53152aaae66a234fb7074e49ae5fcbd90ca879af93abed463d84ecbf",
               "weight": 573,
               "fee": 144
            }
         ],
         "cpfpChecked": true
      }
   ]
}

And then object below many times

{
   "conversions": {
      "AED": 0,
      "AUD": 29272.26,
      "BDT": 0,
      "BHD": 0,
      "BMD": 0,
      "BRL": 103870.78,
      "CAD": 26210.21,
      "CHF": 19514.4,
      "CLP": 0,
      "CNY": 0,
      "CZK": 0,
      "DKK": 0,
      "EUR": 19187.96,
      "GBP": 16515.16,
      "HKD": 159675.03,
      "HUF": 0,
      "IDR": 300581142.86,
      "ILS": 0,
      "INR": 0,
      "JPY": 2747821.51,
      "KRW": 26367417.04,
      "KWD": 0,
      "LKR": 0,
      "MMK": 0,
      "MXN": 0,
      "MYR": 88916.24,
      "NGN": 10403417.36,
      "NOK": 0,
      "NZD": 32276.01,
      "PHP": 0,
      "PKR": 0,
      "PLN": 0,
      "RUB": 1083887.16,
      "SAR": 0,
      "SEK": 0,
      "SGD": 28467.76,
      "THB": 0,
      "TRY": 351400.23,
      "TWD": 0,
      "UAH": 648703.86,
      "USD": 20162.47,
      "VND": 0,
      "ZAR": 326427.28
   }
}

from mempool.js.

nk1tz avatar nk1tz commented on July 20, 2024

I can confirm what @justficks is saying. Using track-address will deliver address-transactions payload when a transaction involving the address is seen in mempool but will not deliver block-transactions payload when the transaction is mined into a block.

@wiz we'd really like to depend on this functionality for Zaprite. Any chance we can get some eyes on this?

Thank you!

from mempool.js.

Aervue avatar Aervue commented on July 20, 2024

Any update on this?

from mempool.js.

tajelp avatar tajelp commented on July 20, 2024

@wiz It seems this is not fixed yet because I keep only receiving the conversions. Can you confirm? When can it be fixed?

from mempool.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.