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.eth.isSyncing

该函数将在每次同步开始、更新和停止时调用指定的回调函数。

调用方法:

web3.eth.isSyncing(callback);

返回值:

返回对象syncing具有如下方法:

  • syncing.addCallback(): 添加另一个回调函数, 当节点开始或停止同步时将被调用
  • syncing.stopWatching(): 停止调用回调函数

回调函数的返回值:

  • Boolean - 当同步开始时返回true,停止时返回false
  • Object - 在同步过程中将返回syncing对象,有以下字段:
    • startingBlock: Number - 同步开始时的块号
    • currentBlock: Number - 当前已经同步的最后块号
    • highestBlock: Number - 预估需要同步的块号

示例代码:

web3.eth.isSyncing(function(error, sync){
    if(!error) {
        // stop all app activity
        if(sync === true) {
           // we use `true`, so it stops all filters, but not the web3.eth.syncing polling
           web3.reset(true);

        // show sync info
        } else if(sync) {
           console.log(sync.currentBlock);

        // re-gain app operation
        } else {
            // run your app init function...
        }
    }
});