Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Node.JS IPFS identify the most recent message received from a peer

I'm building a P2P messaging platform using Node.JS, IPFS (the web3 decentralized blockchain module), and ipfs-http-client.

I'm trying to identify and print only the most recent message sent to an IPFS topic by a user with a peerId as specified in the variable peerId.

The code below seems to print all the messages received in the topic.

What is the best way to identify the most recent message sent to the topic by a specified peer?

I'm trying to use seqno or date to identify the most recent message but having trouble understanding how.

Is there a better way to do this?

Thanks in advance!


const IPFS = require('ipfs')
const IpfsHttpClient = require('ipfs-http-client').create;
const uint8ArrayToString = require("uint8arrays/to-string").toString;

let ipfs
let topic=``
let peerId=``

async function nodeConnect (node_url) {

  ipfs = IpfsHttpClient(node_url)

}

...
...

async function subscribe (topic) {

  await nodeConnect('/ip4/.../tcp/5001')

  await ipfs.pubsub.subscribe(topic, msg => {

    const from = msg.from 
    const seqno = uint8ArrayToString(msg.seqno, 'base16')

    if (from === peerId) return console.log(`Ignoring message ${seqno} from self`)

    console.log(`Message ${seqno} from ${from}:`)

    try {

      console.log(JSON.stringify(uint8ArrayToString(msg.data), null, 2))

    } catch (_) {

      console.log(uint8ArrayToString(msg.data, 'base16'))

    }
  })

}

...
...

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!