peerStore.merge dont pass metadata to oher peer

Hi everyone,

I’m having some trouble with js-libp2p. I want to add new information to the metadata field using peerStore.merge, but I can’t seem to get it to work correctly. The goal is to make this new metadata field available to all other peers during the peer:discovery event.

Here’s what I’m trying to do at peer creation time of my peer instance(peerId):

const meta = {my: {meta: 'info'}}
const metaBin = new TextEncoder().encode(JSON.stringify(meta));
await libp2p.peerStore.merge(peerId, {
    metadata: {
      meta: metaBin
    }
})

After running this code, I expect the new metadata field to be visible to other peers during the peer:discovery event, but it doesn’t seem to be propagated.

in other peer:


libp2p.addEventListener('peer:discovery', async e => {
  const peer = e.detail;
  const peerInfo = await libp2p.peerStore.get(peer.id);
  console.log('peerInfo:',peerInfo)

peerInfo contains empty metadata, this is console.log outout:

peerInfo: {
  addresses: [],
  protocols: [],
  metadata: Map(0) {},
  tags: Map(1) { 'bootstrap' => { value: 50, expiry: 1718117050637n } },
  id: PeerId(QmckJMAv2BfATF1FjcqPndJHoWKbqACNoEvmsWN8unxyiG),
  peerRecordEnvelope: undefined
}

Has anyone experienced something similar or have any suggestions on how to resolve this issue? Any advice would be greatly appreciated!

I can’t find any documentation with examples of using peerStore

Thank you very much!