web3.shh.post

调用post()方法向以太坊网络发送whisper消息。

调用方法:

web3.shh.post(object [, callback])

参数:

  • object :Object ,要发送的对象:
    • from: String, 60 Bytes HEX – (optional) The identity of the sender.
    • to: String, 60 Bytes HEX – (optional) The identity of the receiver. When present whisper will encrypt the message so that only the receiver can decrypt it.
    • topics: Array of Strings – Array of topics Strings, for the receiver to identify messages.
    • payload: String|Number|Object – The payload of the message. Will be autoconverted to a HEX string before.
    • priority: Number – The integer of the priority in a range from … (?).
    • ttl: Number – integer of the time to live in seconds.
  • callback :Function,可选的回调函数,设置此参数后函数将采用异步http请求节点API

返回值:

Boolean – 消息成功发送后返回true,否则返回false

示例代码:

var identity = web3.shh.newIdentity();
var topic = 'example';
var payload = 'hello whisper world!';

var message = {
  from: identity,
  topics: [topic],
  payload: payload,
  ttl: 100,
  workToProve: 100 // or priority TODO
};

web3.shh.post(message);

 

发表评论

后才能评论