web3.js手册

web3
web3.isConnected web3.setProvider web3.currentProvider web3.reset web3.sha3 web3.toHex web3.toAscii web3.fromAscii web3.toDecimal web3.fromDecimal web3.fromWei web3.toWei web3.toBigNumber web3.isAddress
web3.version
web3.version.api web3.version.node web3.version.network web3.version.ethereum web3.version.whisper
web3.net
web3.net.listening web3.net.peerCount
web3.shh
web3.shh.post web3.shh.newIdentity web3.shh.hasIdentity web3.shh.newGroup web3.shh.addGroup web3.shh.filter
web3.db
web3.db.putString web3.db.getString web3.db.putHex web3.db.getHex
web3.eth
web3.eth.defaultAccount web3.eth.defaultBlock web3.eth.syncing web3.eth.isSyncing web3.eth.coinbase web3.eth.hashrate web3.eth.gasPrice web3.eth.accounts web3.eth.mining web3.eth.blockNumber web3.eth.register web3.eth.unRegister web3.eth.getBalance web3.eth.getStorageAt web3.eth.getCode web3.eth.getBlock web3.eth.getBlockTransactionCount web3.eth.getUncle web3.eth.getBlockUncleCount web3.eth.getTransaction web3.eth.getTransactionFromBlock web3.eth.getTransactionReceipt web3.eth.getTransactionCount web3.eth.sendTransaction web3.eth.sendRawTransaction web3.eth.sign web3.eth.call web3.eth.estimateGas web3.eth.filter web3.eth.Contract web3.eth.namereg
iban
web3.eth.sendIBANTransaction web3.eth.iban web3.eth.iban.fromAddress web3.eth.iban.fromBban web3.eth.iban.createIndirect web3.eth.iban.isValid web3.eth.iban.isDirect web3.eth.iban.isIndirect web3.eth.iban.checksun web3.eth.iban.institution web3.eth.iban.client web3.eth.iban.address web3.eth.iban.toString
compiler
web3.eth.getCompilers web3.eth.compile.solidity web3.eth.compile.lll web3.eth.compile.serpent
在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

web3.shh.filter

调用web3.ssh.filter()方法来监听接收的whisper消息。

调用方法:

web3.shh.filter(options[,callback])

参数:

  • options:Object,过滤器选项:
    • topics: 主题字符串数组,用来过滤消息,可以如下组合:
      • ['topic1', 'topic2'] == 'topic1' && 'topic2'
      • ['topic1', ['topic2', 'topic3']] == 'topic1' && ('topic2' || 'topic3')
      • [null, 'topic1', 'topic2'] == ANYTHING && 'topic1' && 'topic2' -> null works as a wildcard
    • to: Filter by identity of receiver of the message. If provided and the node has this identity, it will decrypt incoming encrypted messages.
  • callback:Function ,可选的回调函数,当设置此参数后将采用异步http请求节点旳API

回调函数的返回值:

Object - 接收到的消息:

  • from: String, 60字节,消息发送者
  • to: String, 60字节,消息接受者
  • expiry: Number,消息过期时间,秒为单位
  • ttl: Number,消息存活时间,秒为单位
  • sent: Number ,消息发送时间,unix时间戳格式
  • topics: Array of String,消息包含的主题字符串数组
  • payload: String,消息的载荷内容
  • workProved: Number ,消息发送前需要完成的任务

示例代码:

var filter = web3.shh.filter(options)

// watch for changes
filter.watch(function(error, result){
  if (!error)
    console.log(result);
});