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.getBlock

返回指定编号或哈希的块。

调用方法:

web3.eth.getBlock(blockHashOrBlockNumber [, returnTransactionObjects] [, callback])

参数:

  • blockHashOrBlockNumber:String|Number,块号或哈希值,或者为以下字符串常量:"earliest"、"latest" 或"pending"。
  • returnTransactionObjects:Boolean,可选,默认值为false,如果设置为true,返回的快中将包含所有的交易对象, 否则仅返回交易哈希。
  • callback:Function,可选,当使用回调函数时将采用异步HTTP请求来访问节点。

返回值:

Object - 块对象:

  • number: Number - 块编号,当块处于pending状态时,值为null
  • hash: String, 32字节,块哈希,当块处于pending状态时,值为null
  • parentHash: String, 32字节,父块的哈希
  • nonce: String, 8字节,生成的POW哈希,块处于pending状态时,值为null
  • sha3Uncles: String, 32字节, 块中叔伯数据的SHA3值
  • logsBloom: String, 256字节,块中日志的bloom filter,当块处于pending状态时,值为null
  • transactionsRoot: String, 32字节,块交易树的根节点
  • stateRoot: String, 32字节,块最终状态树的根节点
  • miner: String, 20字节,接收挖矿奖励的矿工地址
  • difficulty: BigNumber , 块难度
  • totalDifficulty: BigNumber , 截止到本块的全链总难度
  • extraData: String ,块中的额外数据
  • size: Number,按字节计算的块大小
  • gasLimit: Number,本块允许的最大gas消耗量
  • gasUsed: Number ,块中所有交易使用的gas总量
  • timestamp: Number,块校验unix时间戳
  • transactions: Array,交易对象数组,或者是32字节的交易哈希值,取决于参数returnTransactionObjects的值
  • uncles: Array,叔伯块的哈希数组

示例代码:

var info = web3.eth.getBlock(3150);
console.log(info);
/*
{
  "number": 3,
  "hash": "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46",
  "parentHash": "0x2302e1c0b972d00932deb5dab9eb2982f570597d9d42504c05d9c2147eaf9c88",
  "nonce": "0xfb6e1a62d119228b",
  "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "transactionsRoot": "0x3a1b03875115b79539e5bd33fb00d8f7b7cd61929d5a3c574f507b8acf415bee",
  "stateRoot": "0xf1133199d44695dfa8fd1bcfe424d82854b5cebef75bddd7e40ea94cda515bcb",
  "miner": "0x8888f1f195afa192cfee860698584c030f4c9db1",
  "difficulty": BigNumber,
  "totalDifficulty": BigNumber,
  "size": 616,
  "extraData": "0x",
  "gasLimit": 3141592,
  "gasUsed": 21662,
  "timestamp": 1429287689,
  "transactions": [
    "0x9fc76417374aa880d4449a1f7f31ec597f00b1f6f3dd2d66f4c9c6c445836d8b"
  ],
  "uncles": []
}
*/