This repository was archived by the owner on Mar 5, 2025. It is now read-only.
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
Cannot subscribe to more than one topic #1361
Closed
Description
I'm not sure if this is a bug or if I'm doing it wrong but when I subscribe to multiple topics using the whisper API but I am only getting messages for the "last topic" in the topics array.
So the tldr; is in my call to shh.subscribe
if I have:
topics: [topic, topic2, topic3]
And in my call to shh.post
, I will only recieve messages from topic3
. If you just alter the order of the topics in the array and the common thread is that its always the "last" topic.
I am running geth in docker with the --shh
flag enabled.
Here is my full code:
import Web3 from 'web3'
;(async function main () {
const web3 = new Web3()
web3.setProvider('ws://localhost:8546')
web3.eth.defaultAccount = await web3.eth.getCoinbase()
const version = await web3.shh.getVersion()
console.log({ version })
const info = await web3.shh.getInfo()
console.log({ info })
const symKey = await web3.shh.newSymKey()
const keyPair = await web3.shh.newKeyPair()
const topic1 = '0xffaadd11'
const topic2 = '0xffaadd22'
const topic3 = '0xffaadd33'
const subscription = await web3.shh.subscribe('messages', {
symKeyID: symKey,
topics: [topic1, topic2, topic3] // only last topic here gets messages
})
.on('data', data => console.log(new Buffer(data.payload.replace(/^0x/, ''), 'hex').toString('utf8')))
await web3.shh.post({
symKeyID: symKey,
sig: keyPair,
ttl: 100,
topic: topic1,
payload: `0x${new Buffer(topic1).toString('hex')}`,
powTime: 3,
powTarget: 0.5
})
await web3.shh.post({
symKeyID: symKey,
sig: keyPair,
ttl: 100,
topic: topic2,
payload: `0x${new Buffer(topic2).toString('hex')}`,
powTime: 3,
powTarget: 0.5
})
await web3.shh.post({
symKeyID: symKey,
sig: keyPair,
ttl: 100,
topic: topic3,
payload: `0x${new Buffer(topic3).toString('hex')}`,
powTime: 3,
powTarget: 0.5
})
})()
Output:
01:53:35:justin:/mnt/e/code/erc/apps/api$ node -r @babel/register .
{ version: '5.0' }
{ info: { memory: 915, messages: 0, minPow: 0.2, maxMessageSize: 1048576 } }
0xffaadd33
Metadata
Metadata
Assignees
Labels
No labels