- geth version: 1.8.15-unstable
- Python: 3.5
- OS: osx/linux
I have followed this answer.
On the answer's approach, I observe that each node can only send message to itself and other nodes don't filter/see those messages. For example, when node-1 sends a message to the network; it won't show up on the node-2 such that node-2's web3.shh.info{memory} remains 0, where I assume that it never catches the message.
I have tried using Web3.js and Web3.py where sent message on Node_1 does not show up on Node_2.
=> This is as far as I came by using Web3.js:
The way I start geth:
geth --syncmode fast --cache=1024 --shh --datadir $DATADIR/private --rpcaddr 127.0.0.1 --rpc --rpcport 8545 --rpccorsdomain="*" --networkid 12345 --rpcapi admin,eth,net,web3,debug,personal,shh
On node-1's geth-client:
generatedSymKey=shh.generateSymKeyFromPassword("hello");
symKey=shh.getSymKey(generatedSymKey)
symKeyID=shh.addSymKey(symKey) //ex: "d5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5"
filter = web3.shh.newMessageFilter(
{symKeyID: symKeyID, topic: '0x07678231'},
function(err, res) {console.log(web3.toUtf8(res.payload))});
On node-2's geth-client:
generatedSymKey=shh.generateSymKeyFromPassword("hello")
symKey=shh.getSymKey(generatedSymKey)
symKeyID=shh.addSymKey(symKey) //ex: "c4c4cecf6ad9499c2386b8ce6416f44684e042e491726b38315646c0b4afadc6"
filter = web3.shh.newMessageFilter(
{symKeyID: symKeyID, topic: '0x07678231'},
function(err, res) {console.log(web3.toUtf8(res.payload))});
Then, node-1 sends message to the network, where only node-1 receives it but node-2 does not.
Following code is run on node-1's geth-client:
node-1's symKeyID is given:
web3.shh.post({
symKeyID: 'd5212e736703afbb21246e8acd192e4345ea910398544d765ed6b49f0ec524b5', //symKeyID of the node-1
ttl: 10,
topic: '0x07678231',
powTarget: 2.01,
powTime: 2,
payload: web3.fromAscii("Hello there!")
});
=> This is as far as I came by using Web3.py:
Node_1 runs shh_filter.get_new_entries()
in order to catch messages but len(received_messages) returns 0, where there is no message is received and web3.shh.info{memory} remains 0.
On node-1:
from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('http://localhost:8545'))
from web3.shh import Shh
Shh.attach(web3, "shh")
import time, sys;
from hexbytes import (
HexBytes,
)
receiver = web3.shh.newKeyPair()
receiver_pub = web3.shh.getPublicKey(receiver)
print('receiverPubK: ' + receiver_pub);
topic = '0x07678231'
shh_filter = web3.shh.newMessageFilter({
'privateKeyID': receiver,
'topics': [topic]
})
input("Press Enter to continue...");
received_messages = [];
received_messages = shh_filter.get_new_entries()
print(len(received_messages)) # Returns '0'
print(web3.shh.info.memory) # Returns '0'
Output:
receiverPubK: 0x04226d96bf9857ac0ba429c1e8b480a2811ce47cb526dbd3829d7586e5cae740198ba291f3eca0f279f82db8a136be90ea9ec629ed6cd1d45cc7f873159811757d
Press Enter to continue...
After Node_1's messages are sent; I have copied printed receiverPublicKey into receiver_pub variable on the following code. I run following code on Node 2. Node 2 sends a message to the network. Later I press enter on the Node_1 and any of those messages does not show up on theNode_1:
On node-2:
from web3 import Web3, HTTPProvider
web3 = Web3(HTTPProvider('http://localhost:8545'))
from web3.shh import Shh
Shh.attach(web3, "shh")
import time, sys;
from hexbytes import (
HexBytes,
)
receiver_pub='0x04226d96bf9857ac0ba429c1e8b480a2811ce47cb526dbd3829d7586e5cae740198ba291f3eca0f279f82db8a136be90ea9ec629ed6cd1'; # obtained from node_1 and assigned here.
topic = '0x07678231'
payloads = [web3.toHex(text="test message :)"), web3.toHex(text="2nd test message")]
web3.shh.post({
'powTarget': 2.5,
'powTime': 2,
'ttl': 60,
'payload': payloads[0],
'topic': topic,
'pubKey': receiver_pub
})
time.sleep(1)
web3.shh.post({
'powTarget': 2.5,
'powTime': 2,
'ttl': 60,
'payload': payloads[1],
'topic': topic,
'pubKey': receiver_pub
})
[Q] How could I send a whisper message from one node to another? What do I do wrong on my approaches?
On the reciever shh.info.memory remains 0 when sender node posts a message.
Please note that, I have opened issue on Web3.py and go-ethereum but no one responded. I have also tried one node is one of those nodes was bootnode and the other one needs to have its enode address in --bootnodes, which also did not work.
- Opened Web3.py issue.
- Opened go-ethereum issue.
- Opened Whisper issue

shh.generateSymKeyFromPassword("password")When I'm using difference pwd then node-2 cannot receive msg from node-1
– Tony Dang Sep 07 '18 at 08:37https://github.com/hadv/whisper-v6-demo
– Tony Dang Sep 07 '18 at 09:17ws://localhost:8545instead ofhttp://localhost:8545– Tony Dang Sep 07 '18 at 09:21https://web3js.readthedocs.io/en/1.0/web3-shh.html#web3-shh
– Tony Dang Sep 07 '18 at 09:31Web3 = require("web3"); web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545" ));– alper Sep 07 '18 at 10:02
– Tony Dang Sep 07 '18 at 10:03// change provider web3.setProvider('ws://localhost:8546');gethcmd to the question for everyone can know with which options your node was started. – Tony Dang Sep 07 '18 at 10:05gethcommand. – alper Sep 07 '18 at 12:00--ws --wsaddr "0.0.0.0" --wsapi "eth,net,web3,admin,shh" --wsorigins "*" --wsport 8546to allow connecting by websocket – Tony Dang Sep 07 '18 at 12:03--ws --wsaddr "0.0.0.0" --wsapi "eth,net,web3,admin,shh" --wsorigins "*"than with that and see does it make a difference. On the code you shared I did not see any--wsport 8546? Also I think using--wsaddr "127.0.0.1"should be more safe. – alper Sep 07 '18 at 12:09const web3 = new Web3('ws://localhost:8546');– Tony Dang Sep 07 '18 at 12:20subscriber.jsdoes not returns the posted message. And I am pretty sure this (https://github.com/achiko/whisper-v6-test) will not work on different host that try to send message to each other. – alper Sep 07 '18 at 12:31messageFilterinstead ofsubscribe. – alper Sep 07 '18 at 13:28const web3 = new Web3(new Web3.providers.WebsocketProvider("ws://localhost:8546"));then it worked properly; so I think we must usewebsocket, nothttp– Tony Dang Sep 07 '18 at 14:12