---
title: "eth_getBlockByNumber"
description: "按区块号返回区块信息（BSC）"
url: "https://blockreq.com/docs/zh-cn/build/api-reference/bsc/eth_getBlockByNumber/"
---

# eth_getBlockByNumber

**网络：** BSC · 主网 · Chain ID `56`（`0x38`）

**计为 1 个 Request。** 计费规则见 [Request Counting](https://blockreq.com/docs/zh-cn/pricing/request-counting/index.md)。

根据区块号返回区块信息。

## 参数

1. `QUANTITY|TAG` — 区块号，或字符串 `"earliest"`、`"latest"`、`"safe"`、`"finalized"`、`"pending"`。
2. `Boolean` — `true` 返回完整交易对象，`false` 仅返回交易哈希列表。

## 返回

`Object|null` — 区块对象；查不到时返回 `null`。

| 字段          | 类型     | 说明               |
| ------------- | -------- | ------------------ |
| number        | QUANTITY | 区块号             |
| hash          | DATA     | 区块哈希           |
| parentHash    | DATA     | 父区块哈希         |
| timestamp     | QUANTITY | Unix 时间戳        |
| gasUsed       | QUANTITY | 已使用 Gas         |
| gasLimit      | QUANTITY | Gas 上限           |
| baseFeePerGas | QUANTITY | 基础费（EIP-1559） |
| transactions  | Array    | 交易哈希或交易对象 |

## 请求

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": ["latest", false],
  "id": 1
}
```

## 响应

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "number": "0x134e82a",
    "hash": "0xabc...def",
    "parentHash": "0x123...456",
    "timestamp": "0x65a1b2c3",
    "gasUsed": "0x1234",
    "gasLimit": "0x1c9c380",
    "baseFeePerGas": "0x3b9aca00",
    "transactions": ["0x..."]
  }
}
```

## 代码示例

**cURL**

```bash
curl -X POST https://bsc-rpc.blockreq.com/v1/rpc/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}'
```

**TypeScript**

```typescript
const response = await fetch("https://bsc-rpc.blockreq.com/v1/rpc/public", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": [
    "latest",
    false
  ],
  "id": 1
}),
});
const data = await response.json();
console.log(data.result);
```

**Python**

```python
import requests

response = requests.post(
    "https://bsc-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_getBlockByNumber",
  "params": [
    "latest",
    false
  ],
  "id": 1
}
)
print(response.json()["result"])
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func main() {
	payload := []byte(`{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest",false],"id":1}`)
	resp, err := http.Post(
		"https://bsc-rpc.blockreq.com/v1/rpc/public",
		"application/json",
		bytes.NewBuffer(payload),
	)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	body, _ := io.ReadAll(resp.Body)
	var result map[string]interface{}
	json.Unmarshal(body, &result)
	fmt.Println(result["result"])
}
```

**viem**

```typescript
import { createPublicClient, http } from "viem";

const client = createPublicClient({
  transport: http("https://bsc-rpc.blockreq.com/v1/rpc/public"),
});

const result = await client.request({
  method: "eth_getBlockByNumber",
  params: ["latest",false],
});
console.log(result);
```

**Foundry**

```bash
cast rpc --rpc-url https://bsc-rpc.blockreq.com/v1/rpc/public eth_getBlockByNumber latest false
```

**Hardhat**

```javascript
const { ethers } = require("hardhat");

async function main() {
  const provider = new ethers.JsonRpcProvider("https://bsc-rpc.blockreq.com/v1/rpc/public");
  const result = await provider.send("eth_getBlockByNumber", ["latest",false]);
  console.log(result);
}

main();
```
