Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.