Skip to main content

getBlock

Callable

  • getBlock<ReturnFormat>(web3Context: Web3Context<EthExecutionAPI, any>, block?: string | number | bigint | Buffer | ArrayBuffer | Uint8Array, hydrated?: boolean, returnFormat: ReturnFormat): Promise<{ baseFeePerGas?: NumberTypes[ReturnFormat[number]]; difficulty?: NumberTypes[ReturnFormat[number]]; extraData: ByteTypes[ReturnFormat[bytes]]; gasLimit: NumberTypes[ReturnFormat[number]]; gasUsed: NumberTypes[ReturnFormat[number]]; hash?: ByteTypes[ReturnFormat[bytes]]; logsBloom?: ByteTypes[ReturnFormat[bytes]]; miner: ByteTypes[ReturnFormat[bytes]]; mixHash: ByteTypes[ReturnFormat[bytes]]; nonce: NumberTypes[ReturnFormat[number]]; number: NumberTypes[ReturnFormat[number]]; parentHash: ByteTypes[ReturnFormat[bytes]]; receiptsRoot: ByteTypes[ReturnFormat[bytes]]; sha3Uncles: ByteTypes[ReturnFormat[bytes]]; size: NumberTypes[ReturnFormat[number]]; stateRoot: ByteTypes[ReturnFormat[bytes]]; timestamp: NumberTypes[ReturnFormat[number]]; totalDifficulty: NumberTypes[ReturnFormat[number]]; transactions: string[] | { readonly blockHash?: ByteTypes[ReturnFormat["bytes"]] | undefined; readonly blockNumber?: NumberTypes[ReturnFormat["number"]] | undefined; ... 23 more ...; s?: ByteTypes[ReturnFormat["bytes"]] | undefined; }[]; transactionsRoot: ByteTypes[ReturnFormat[bytes]]; uncles: string[] }>

  • Retrieves a Block matching the provided block number, block hash or block tag.


    Type parameters

    Parameters

    • web3Context: Web3Context<EthExecutionAPI, any>

      (Web3Context) Web3 configuration object that contains things such as the provider, request manager, wallet, etc.

    • block: string | number | bigint | Buffer | ArrayBuffer | Uint8Array = web3Context.defaultBlock

      The BlockNumberOrTag (defaults to Web3Eth.defaultBlock) or block hash of the desired block.

    • hydrated: boolean = false

      If specified true, the returned block will contain all transactions as objects. If false it will only contain transaction hashes.

    • returnFormat: ReturnFormat

      (DataFormat defaults to DEFAULT_RETURN_FORMAT) Specifies how the return data should be formatted (does not format transaction objects or hashes).

    Returns Promise<{ baseFeePerGas?: NumberTypes[ReturnFormat[number]]; difficulty?: NumberTypes[ReturnFormat[number]]; extraData: ByteTypes[ReturnFormat[bytes]]; gasLimit: NumberTypes[ReturnFormat[number]]; gasUsed: NumberTypes[ReturnFormat[number]]; hash?: ByteTypes[ReturnFormat[bytes]]; logsBloom?: ByteTypes[ReturnFormat[bytes]]; miner: ByteTypes[ReturnFormat[bytes]]; mixHash: ByteTypes[ReturnFormat[bytes]]; nonce: NumberTypes[ReturnFormat[number]]; number: NumberTypes[ReturnFormat[number]]; parentHash: ByteTypes[ReturnFormat[bytes]]; receiptsRoot: ByteTypes[ReturnFormat[bytes]]; sha3Uncles: ByteTypes[ReturnFormat[bytes]]; size: NumberTypes[ReturnFormat[number]]; stateRoot: ByteTypes[ReturnFormat[bytes]]; timestamp: NumberTypes[ReturnFormat[number]]; totalDifficulty: NumberTypes[ReturnFormat[number]]; transactions: string[] | { readonly blockHash?: ByteTypes[ReturnFormat["bytes"]] | undefined; readonly blockNumber?: NumberTypes[ReturnFormat["number"]] | undefined; ... 23 more ...; s?: ByteTypes[ReturnFormat["bytes"]] | undefined; }[]; transactionsRoot: ByteTypes[ReturnFormat[bytes]]; uncles: string[] }>

    A Block object matching the provided block number or block hash.

    web3.eth.getBlock(0).then(console.log);
    > {
    hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
    parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
    sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
    miner: '0x0000000000000000000000000000000000000000',
    stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
    transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
    receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    difficulty: 1n,
    number: 0n,
    gasLimit: 30000000n,
    gasUsed: 0n,
    timestamp: 1658281638n,
    extraData: '0x',
    mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
    nonce: 0n,
    totalDifficulty: 1n,
    baseFeePerGas: 1000000000n,
    size: 514n,
    transactions: [],
    uncles: []
    }

    web3.eth.getBlock(
    "0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d",
    false,
    { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }
    ).then(console.log);
    > {
    hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d',
    parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
    sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
    miner: '0x0000000000000000000000000000000000000000',
    stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4',
    transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
    receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    difficulty: 1,
    number: 0,
    gasLimit: 30000000,
    gasUsed: 0,
    timestamp: 1658281638,
    extraData: '0x',
    mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
    nonce: 0,
    totalDifficulty: 1,
    baseFeePerGas: 1000000000,
    size: 514,
    transactions: [],
    uncles: []
    }