eth_getBlockByNumber
https://api.triport.io/v1/ethereumReturns information about a block on the Ethereum chain, selected by block number or by a named block tag.
eth_getBlockByNumber returns the full block object for a given block, identified
either by a 0x-prefixed hexadecimal block number or by one of the supported
named tags. It is the standard way to read a historical or current block,
including its header fields and its list of transactions.
The second parameter controls how much transaction detail comes back. When
fullTransactions is false, the transactions array contains only transaction
hashes (cheaper, smaller payload). When it is true, the array contains the
fully expanded transaction objects for every transaction in the block.
If no block matches the requested number or tag — for example a height that has
not been produced yet — the method returns null rather than an error. Always
handle the null case before reading fields off the result.
Parameters
Pass a positional array of exactly two elements.
blockParameterstringrequired0x-prefixed hex block number (e.g. 0x149e2c1) or one of the named tags: latest, earliest, pending, safe, finalized.fullTransactionsbooleanrequiredtrue, returns full transaction objects in transactions. If false, returns only transaction hashes.Response
Response fields
| Field | Type | Description |
|---|---|---|
number | string | Block number as a 0x-prefixed hex string. null for pending blocks. |
hash | string | 32-byte block hash. null for pending blocks. |
parentHash | string | Hash of the parent block. |
nonce | string | 8-byte proof-of-work nonce. null for pending blocks. |
sha3Uncles | string | SHA3 of the uncles data in the block. |
logsBloom | string | Bloom filter for the logs in the block. null for pending blocks. |
transactionsRoot | string | Root of the transaction trie. |
stateRoot | string | Root of the final state trie. |
receiptsRoot | string | Root of the receipts trie. |
miner | string | Address of the block's fee/coinbase recipient. |
difficulty | string | Block difficulty (0x0 post-merge). |
totalDifficulty | string | Total difficulty of the chain up to this block. |
extraData | string | Extra data field of the block. |
size | string | Block size in bytes, hex-encoded. |
gasLimit | string | Maximum gas allowed in the block. |
gasUsed | string | Total gas used by all transactions in the block. |
baseFeePerGas | string | Base fee per gas (post-EIP-1559 blocks). |
timestamp | string | Unix timestamp of block collation, hex-encoded. |
transactions | array | Transaction hashes (when fullTransactions is false) or full transaction objects (when true). |
uncles | array | Array of uncle block hashes. |
The full result is null when no block matches the requested number or tag.
Errors
| Code | Meaning | When it happens |
|---|---|---|
-32001 | trial_expired | The account's trial period has ended. |
-32003 | rate_limited | The per-tier RPS limit was exceeded. Back off and retry. |
See errors.md for the full error envelope and handling guidance.
Examples
JavaScript (fetch)
const res = await fetch("https://api.triport.io/v1/ethereum", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.TRIPORT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "eth_getBlockByNumber",
params: ["latest", false],
}),
});
const { result } = await res.json();
if (result === null) {
console.log("block not found");
} else {
console.log("block", parseInt(result.number, 16), "tx count:", result.transactions.length);
}TypeScript SDK (@triport/sdk)
import { Triport } from "@triport/sdk";
const client = new Triport({ apiKey: process.env.TRIPORT_API_KEY! });
// Fetch the latest block with full transaction objects.
const block = await client.ethereum.request<Record<string, unknown> | null>(
"eth_getBlockByNumber",
["latest", true],
);
if (block) {
console.log("block", parseInt(block.number as string, 16));
}Python (triport-sdk)
import os
from triport import Triport
client = Triport(api_key=os.environ["TRIPORT_API_KEY"])
# Fetch a specific block by hex number, hashes only.
block = client.ethereum.request("eth_getBlockByNumber", ["0x149e2c1", False])
if block is None:
print("block not found")
else:
print("block", int(block["number"], 16), "tx count:", len(block["transactions"]))Notes
- All numeric block fields (
number,gasUsed,timestamp, etc.) are hex strings — convert with base 16 before arithmetic. - A
nullresult is normal, not an error: it means the requested block does not exist yet (e.g. a future height). Check fornullbefore dereferencing. - Setting
fullTransactionstotruesubstantially increases the response size on busy blocks; preferfalsewhen you only need transaction hashes. eth_getBlockByNumberis available on the free tier (eth_read_rpccategory). Rate limiting is RPS-per-tier with burst; there is no daily quota. A-32003 rate_limitederror means you should back off and retry shortly.- To find the current chain head before requesting a concrete block, call
eth_blockNumber. To look a block up by its hash instead
of its number, use
eth_getBlockByHash.