Skip to content

Instantly share code, notes, and snippets.

@frozeman
Created June 27, 2017 15:31
Show Gist options
  • Save frozeman/423e91f7a613be58bbbe344ba1f7f89b to your computer and use it in GitHub Desktop.
Save frozeman/423e91f7a613be58bbbe344ba1f7f89b to your computer and use it in GitHub Desktop.
Whisper web3.js 1.0 api test
var net = require('net');
var Web3 = require('./src/index.js'); var web3 = new Web3(new Web3.providers.IpcProvider('/Users/frozeman/Library/Ethereum/geth.ipc', net));
var shh = web3.shh;
var identities = [];
var subscription = null;
Promise.all([
shh.newSymKey().then((id) => {identities.push(id);}),
shh.newKeyPair().then((id) => {identities.push(id);})
]).then(() => {
return shh.getPublicKey(identities[1]);
}).then((id) => {
identities.push(id);
}).then(() => {
subscription = shh.subscribe("messages", {
symKeyID: identities[0],
topics: ['0xffaadd11']
}).on('data', console.log);
}).then(() => {
shh.post({
symKeyID: identities[0],
sig: identities[1],
ttl: 10,
topic: '0xffaadd11',
payload: '0xffffffdddddd1122',
powTime: 3,
powTarget: 0.5
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment