ethereum / ethereum/execution-apis

Proposal: eth_getBlockState - returns chainId, block number, block timestamp and stateId

Open
#629 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Io
Stars
1.1k
Forks
530
Avg merge
5d 8h
Merged PRs (30d)
9

Description


# [`eth_getBlockState`](#)

## Motivation

DApps will request chainId and blocknumber continuously (e.g. look at uniswap dapp network console). There is not any RPC methods that return ChainId information outside of eth_chainId. This seems useful, so include it in block number and block timestamp response and we got this.

- [Block State JSON-RPC Method Specification](#block-state-json-rpc-method-specification)
* [Method Name](#method-name)
* [Description](#description)
* [Parameters](#parameters)
* [Returns](#returns)
* [Example Request](#example-request)
* [Example Response](#example-response)
* [Error Codes](#error-codes)
* [Specification Notes](#specification-notes)
* [State Diagram](#state-diagram)
* [Additional Examples](#additional-examples)
+ [Request with "earliest" block](#request-with-earliest-block)
+ [Response for "earliest" block](#response-for-earliest-block)
+ [Error Response Example](#error-response-example)


## Method Name
`eth_getBlockState`


## Description
Returns the chain ID, block number, and block state and block timestamp for the specified block parameter.

> [!NOTE]
> Need to add block.timestamp in response and request, just thought of it as I am typing this meow


## Parameters
1. `blockParameter` - An object containing one of the following block state identifiers:

- `{ "blockNumber": "earliest" }` - Earliest/genesis block
- `{ "blockNumber": "latest" }` - Latest canonical block
- `{ "blockNumber": "pending" }` - Pending state/transactions
- `{ "blockNumber": "safe" }` - Most recent safe block
- `{ "blockNumber": "finalized" }` - Most recent finalized block


## Returns

Object - A block state object containing:
- `chainId`: STRING - The chain ID in hexadecimal format
- `blockNumber`: STRING - The block number in hexadecimal format
- `blockState`: STRING - One of: "earliest", "latest", "pending", "safe", "finalized"


## Example Request
```json
{
"jsonrpc": "2.0",
"method": "eth_getBlockState",
"params": [
{
"blockNumber": "latest"
}
],
"id": 1
}
```


## Example Response
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"chainId": "0x1",
"blockNumber": "0xf4240",
"blockState": "latest"
}
}
```


## Error Codes
| Code | Message | Description |
|------|---------|-------------|
| -32700 | Parse error | Invalid JSON |
| -32600 | Invalid Request | JSON is not a valid request object |
| -32601 | Method not found | Method does not exist |
| -32602 | Invalid params | Invalid method parameters |
| -32603 | Internal error | Internal JSON-RPC error |


## Specification Notes

1. **EIP-1898 Compliance**
- The block parameter MUST be specified as an object
- The object MUST contain a `blockNumber` field
- The value MUST be one of the specified string literals

2. **EIP-1474 Compliance**
- Method name follows the `eth_` namespace convention
- Adheres to standard JSON-RPC 2.0 format
- All numeric values are hexadecimal encoded
- Error codes follow standard ranges

3. **Additional Requirements**
- The response MUST include all three fields: chainId, blockNumber, and blockState
- Chain ID MUST be returned in hexadecimal format
- Block number MUST be returned in hexadecimal format
- Block state MUST be one of the five specified string literals

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.