首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在web3.js中使用Whisper

在web3.js中使用Whisper
EN

Ethereum用户
提问于 2017-12-02 23:25:23
回答 2查看 1.2K关注 0票数 3

我一直在努力弄清楚如何使用web3与窃窃私语交互。我已经能够成功地使用geth console发送(并接收)一条消息,但无法使用web3.js进行同样的操作。

你会提供一个短的JavaScript片段,成功地发送和接收一条耳语消息吗?

EN

回答 2

Ethereum用户

发布于 2018-02-08 09:59:02

在运行Geth时,(我使用了geth --rinkeby --fast --cache=512 console --shh --rpc --rpccorsdomain '*' --ws --wsorigins '*')和浏览器中的web3.js v1,输入浏览器控制台:

代码语言:javascript
复制
> web3.shh.setProvider("ws://localhost:8546") // must use websockets (read this on https://ethereum.stackexchange.com/a/34840/6014)
> web3.shh.newKeyPair().then(console.log) // logs key pair
> web3.shh.subscribe("messages", {privateKeyID: keyPair}, (err, msg) => console.log("msg received!", msg)) // returns subscription that will log the message when it's received
> web3.shh.getPublicKey(keyPair).then(console.log) // logs public key

> web3.shh.post({pubKey: publicKey, ttl: 10, payload: '0xffffffdddddd1122', powTime: 3, powTarget: 0.5}) // sends the message
票数 2
EN

Ethereum用户

发布于 2017-12-04 16:46:44

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/32314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档