Created
February 28, 2017 18:40
-
-
Save achiko/ca2bbb7536249d60b1fc078db39a395c to your computer and use it in GitHub Desktop.
whisper sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://pokereum.cloudapp.net:8545")); | |
var identity = web3.shh.newIdentity(); | |
var topic = 'pokereum'; | |
// build message object | |
var message = { | |
//from: identity, | |
topics: [web3.fromAscii(topic)], | |
payload: web3.fromAscii('hey Pokereummmm !!! '), | |
ttl: 600, | |
// priority: 100 | |
}; | |
// 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) ); | |
}) | |
web3.shh.post(message, function (err, result) { | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment