【代码】分享一段扫描区块信息的代码

   for (var i = 3169350; i <= 3169400; i++) {
        console.log("Searching block " + i);
        var block = await cfx.getBlockByEpochNumber(i, true);
        var count = 0;

        if (block != null && block.transactions != null) {
            if(block.transactions!=null){
            block.transactions.forEach(function (e) {     
              console.log(" tx hash : " + e.hash + "\n"
                + " nonce : " + e.nonce + "\n"
                + " blockHash : " + e.blockHash + "\n"
                + " blockNumber : " + e.blockNumber + "\n"
                + " transactionIndex: " + e.transactionIndex + "\n"
                + " from : " + e.from + "\n" 
                + " to : " + e.to + "\n"
                + " gasPrice : " + e.gasPrice + "\n"
                + " gas : " + e.gas + "\n"
                + " input : " + e.input
                + "--------------------------------------------------------------------------------------------"
                );count++;
            })
            }
            else{
                console.log("No transaction. " + i);
            }
        }
        
     
    }
    console.log("交易数量: " + count);

仅贴出了遍历区块信息的(这次没写注释,但问题不大都能看懂),其他代码可以参照之前的新手0-1教程(见下方帖子),里面有关于开发环境、工具、调用链、账户、合约等所有代码和说明。

现在,你们可以查找链上全部的信息了。

这是运行结果截图

1 Like