eth_getBlockByNumber

Retrieves a block by its number or tag from the Ethereum blockchain.

Example

import { getRpcClient, eth_getBlockByNumber } from "thirdweb/rpc";
const rpcRequest = getRpcClient({ client, chain });
const block = await eth_getBlockByNumber(rpcRequest, {
blockNumber: 123456,
includeTransactions: true,
});
function eth_getBlockByNumber(request: EIP1193RequestFn<[{ Method: "web3_clientVersion"; Parameters?: undefined; ReturnType: string }, { Method: "web3_sha3"; Parameters: [data: `0x${string}`]; ReturnType: string }, { Method: "net_listening"; Parameters?: undefined; ReturnType: boolean }, { Method: "net_peerCount"; Parameters?: undefined; ReturnType: `0x${string}` }, { Method: "net_version"; Parameters?: undefined; ReturnType: `0x${string}` }]>, params: GetBlockParameters<TIncludeTransactions, TBlockTag>) : Promise<{ baseFeePerGas: null | bigint; blobGasUsed: bigint; difficulty: bigint; excessBlobGas: bigint; extraData: `0x${string}`; gasLimit: bigint; gasUsed: bigint; hash: TBlockTag extends "pending" ? null : `0x${string}`; logsBloom: TBlockTag extends "pending" ? null : `0x${string}`; miner: string; mixHash: `0x${string}`; nonce: TBlockTag extends "pending" ? null : `0x${string}`; number: TBlockTag extends "pending" ? null : bigint; parentBeaconBlockRoot?: `0x${string}`; parentHash: `0x${string}`; receiptsRoot: `0x${string}`; sealFields: Array<`0x${string}`>; sha3Uncles: `0x${string}`; size: bigint; stateRoot: `0x${string}`; timestamp: bigint; totalDifficulty: null | bigint; transactions: TIncludeTransactions extends true ? Array<({ accessList?: undefined; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId?: number; from: string; gas: bigint; gasPrice: bigint; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas?: undefined; maxPriorityFeePerGas?: undefined; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "legacy"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity?: undefined }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice: bigint; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas?: undefined; maxPriorityFeePerGas?: undefined; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip2930"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip1559"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes: readonly Array<`0x${string}`>; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas: bigint; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip4844"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList: SignedAuthorizationList; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip7702"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number })> : Array<`0x${string}`>; transactionsRoot: `0x${string}`; uncles: Array<`0x${string}`>; withdrawals?: Array<Withdrawal>; withdrawalsRoot?: `0x${string}` }>

Parameters

The EIP1193 request function.

Type

let request: EIP1193RequestFn<
[
{
Method: "web3_clientVersion";
Parameters?: undefined;
ReturnType: string;
},
{
Method: "web3_sha3";
Parameters: [data: `0x${string}`];
ReturnType: string;
},
{
Method: "net_listening";
Parameters?: undefined;
ReturnType: boolean;
},
{
Method: "net_peerCount";
Parameters?: undefined;
ReturnType: `0x${string}`;
},
{
Method: "net_version";
Parameters?: undefined;
ReturnType: `0x${string}`;
},
]
>;

The parameters for retrieving the block.

Type

let params: GetBlockParameters<TIncludeTransactions, TBlockTag>;

Returns

let returnType: Promise<{ baseFeePerGas: null | bigint; blobGasUsed: bigint; difficulty: bigint; excessBlobGas: bigint; extraData: `0x${string}`; gasLimit: bigint; gasUsed: bigint; hash: TBlockTag extends "pending" ? null : `0x${string}`; logsBloom: TBlockTag extends "pending" ? null : `0x${string}`; miner: string; mixHash: `0x${string}`; nonce: TBlockTag extends "pending" ? null : `0x${string}`; number: TBlockTag extends "pending" ? null : bigint; parentBeaconBlockRoot?: `0x${string}`; parentHash: `0x${string}`; receiptsRoot: `0x${string}`; sealFields: Array<`0x${string}`>; sha3Uncles: `0x${string}`; size: bigint; stateRoot: `0x${string}`; timestamp: bigint; totalDifficulty: null | bigint; transactions: TIncludeTransactions extends true ? Array<({ accessList?: undefined; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId?: number; from: string; gas: bigint; gasPrice: bigint; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas?: undefined; maxPriorityFeePerGas?: undefined; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "legacy"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity?: undefined }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice: bigint; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas?: undefined; maxPriorityFeePerGas?: undefined; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip2930"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip1559"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList?: undefined; blobVersionedHashes: readonly Array<`0x${string}`>; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas: bigint; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip4844"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number }) | ({ accessList: AccessList; authorizationList: SignedAuthorizationList; blobVersionedHashes?: undefined; blockHash: TBlockTag extends "pending" ? true : false extends true ? null : `0x${string}`; blockNumber: TBlockTag extends "pending" ? true : false extends true ? null : bigint; chainId: number; from: string; gas: bigint; gasPrice?: undefined; hash: `0x${string}`; input: `0x${string}`; maxFeePerBlobGas?: undefined; maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; nonce: number; r: `0x${string}`; s: `0x${string}`; to: null | string; transactionIndex: TBlockTag extends "pending" ? true : false extends true ? null : number; type: "eip7702"; typeHex: null | (`0x${string}`); v: bigint; value: bigint; yParity: number })> : Array<`0x${string}`>; transactionsRoot: `0x${string}`; uncles: Array<`0x${string}`>; withdrawals?: Array<Withdrawal>; withdrawalsRoot?: `0x${string}` }>

A promise that resolves to the requested block.