Skip to content

Instantly share code, notes, and snippets.

@adibas03
Forked from achiko/whisper.js
Last active February 28, 2017 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adibas03/96cb8100fc58b95a91afe9478fa4dbce to your computer and use it in GitHub Desktop.
Save adibas03/96cb8100fc58b95a91afe9478fa4dbce to your computer and use it in GitHub Desktop.
whisper sample
console.log('shh clien ....');
var Web3 = require('Web3');
if(typeof web3 !== 'undefined')
web3 = new Web3(web3.currentProvider);
else
//web3 = new Web3(new Web3.providers.HttpProvider("http://67.205.160.17:3555"));
web3 = new Web3(new Web3.providers.HttpProvider("http://pokereum.cloudapp.net:8545"));
var identity = web3.shh.newIdentity();
var topic = 'pokereum';
// build message object
var message = prep_msg('hey Pokereum!!!');
// setup filter for messages on topic
var filter = web3.shh.filter({
topics: [web3.fromAscii(topic)]
});
// watch for changes on filter
filter.watch(function (err, result) {
console.log( ':',web3.toAscii(result.payload) );
})
//Send Intro
do_post(message);
this.stdin = process.openStdin();
this.stdin.addListener("data", function (d) {
msg = d.toString().trim();
//console.log('New msg:',msg)
do_post(prep_msg(msg));
});
function prep_msg(typ_msg){
return {
//from: identity,
topics: [web3.fromAscii(topic)],
payload: web3.fromAscii(typ_msg),
ttl: 600,
// priority: 100
};
}
function do_post(msg){
web3.shh.post(msg, function (err, result) {
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment