get_block

Fetches a block by decimal height, supported block tag, or block hash. The block defaults to latest and include_transactions defaults to false.

Table functionLive RPC RPC

Example

Live RPC

SELECT number, hash, timestamp
FROM get_block($client);

API reference

get_block(CLIENT) # RPC required

Fetches latest with include_transactions set to false.

Inputs

Name Type Use
client CLIENT

Attached live CLIENT used for the RPC request.

required positional

Result columns

NameType
hashBYTES32

Block hash.

parent_hashBYTES32

Parent block hash.

minerADDRESS

Execution-fee recipient.

numberBLOCK_NUMBER

Block height.

timestampTIMESTAMP

Block time in UTC.

Block metadata row. Returns one row. transactions contains hashes in block order for either transaction mode. transactions_full contains expanded objects only when include_transactions is true. An empty transaction array is represented as NULL in both list columns. A NULL or empty client produces a row in which every column is NULL. A NULL height, an invalid selector, a missing block or a failed RPC request raises.

get_block(CLIENT, BIGINT | VARCHAR) # RPC required

Fetch a block by decimal height, supported block tag or block hash without expanded transactions. A NULL height, a missing block or a failed read raises.

Exact signatures (2)
  • get_block(CLIENT, BIGINT)
  • get_block(CLIENT, VARCHAR)

Inputs

Name Type Use
client CLIENT

Attached live CLIENT used for the RPC request.

required positional
block_number / block_tag_or_hash BIGINT | VARCHAR

BIGINT: Non-negative BIGINT block height. NULL raises; tags and hashes are not accepted. VARCHAR: Decimal height string; latest, pending, earliest, safe, or finalized; or a 66-character block hash beginning with lowercase 0x. An empty value selects latest; NULL raises.

required positional

Result columns

NameType
hashBYTES32

Block hash.

parent_hashBYTES32

Parent block hash.

minerADDRESS

Execution-fee recipient.

numberBLOCK_NUMBER

Block height.

timestampTIMESTAMP

Block time in UTC.

Block metadata row. Returns one row. transactions contains hashes in block order for either transaction mode. transactions_full contains expanded objects only when include_transactions is true. An empty transaction array is represented as NULL in both list columns. A NULL or empty client produces a row in which every column is NULL. A NULL height, an invalid selector, a missing block or a failed RPC request raises.

Overload examples

Live RPC

-- Summarize the provider's finalized block
SELECT
  number,
  length(transactions) AS transaction_count,
  gas_used,
  gas_limit,
  round(100.0 * gas_used::DOUBLE / gas_limit::DOUBLE, 2) AS gas_utilization_pct
FROM get_block($client, 'finalized');
get_block(CLIENT, BIGINT | VARCHAR, BOOLEAN) # RPC required

Fetch a selected block and choose whether transactions_full holds expanded transaction objects.

Exact signatures (2)
  • get_block(CLIENT, BIGINT, BOOLEAN)
  • get_block(CLIENT, VARCHAR, BOOLEAN)

Inputs

Name Type Use
client CLIENT

Attached live CLIENT used for the RPC request.

required positional
block_number / block_tag_or_hash BIGINT | VARCHAR

BIGINT: Non-negative BIGINT block height. NULL raises; tags and hashes are not accepted. VARCHAR: Decimal height string; latest, pending, earliest, safe, or finalized; or a 66-character block hash beginning with lowercase 0x. An empty value selects latest; NULL raises.

required positional
include_transactions BOOLEAN

Requests expanded transaction objects when true. The default is false; NULL is also treated as false.

required positional

Result columns

NameType
hashBYTES32

Block hash.

parent_hashBYTES32

Parent block hash.

minerADDRESS

Execution-fee recipient.

numberBLOCK_NUMBER

Block height.

timestampTIMESTAMP

Block time in UTC.

Block metadata row. Returns one row. transactions contains hashes in block order for either transaction mode. transactions_full contains expanded objects only when include_transactions is true. An empty transaction array is represented as NULL in both list columns. A NULL or empty client produces a row in which every column is NULL. A NULL height, an invalid selector, a missing block or a failed RPC request raises.

Overload examples

Live RPC

-- Largest native-value transfers in the block containing the documented transaction
SELECT
  (tx).hash AS transaction_hash,
  (tx)."from" AS sender,
  (tx)."to" AS recipient,
  format_ether((tx).value) AS eth_value
FROM get_block($client, 25433824, true),
UNNEST(transactions_full) AS expanded(tx)
ORDER BY sort_key((tx).value) DESC
LIMIT 10;

Guidance

Reproducible block reads

Use an explicit block number or block hash when a query must be repeatable.

latest, pending, safe, and finalized can resolve to a different block between runs. Persist the returned number and hash when later queries must use the same snapshot.