---
title: "eth_getBlockByHash"
description: "按区块哈希返回区块信息（Polygon）"
url: "https://blockreq.com/docs/zh-cn/build/api-reference/polygon/eth_getBlockByHash/"
---

# eth_getBlockByHash

**网络：** Polygon · 主网 · Chain ID `137`（`0x89`）

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

根据区块哈希返回区块信息。

## 参数

1. `DATA`（32 字节）— 区块哈希。
2. `Boolean` — `true` 返回完整交易对象，`false` 仅返回交易哈希列表。

## 返回

`Object|null` — 区块对象（结构与 `eth_getBlockByNumber` 相同），查不到时返回 `null`。

## 请求

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getBlockByHash",
  "params": ["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae", false],
  "id": 1
}
```

## 代码示例

**cURL**

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

**TypeScript**

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

**Python**

```python
import requests

response = requests.post(
    "https://polygon-bor-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_getBlockByHash",
  "params": [
    "0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
    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_getBlockByHash","params":["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",false],"id":1}`)
	resp, err := http.Post(
		"https://polygon-bor-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://polygon-bor-rpc.blockreq.com/v1/rpc/public"),
});

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

**Foundry**

```bash
cast rpc --rpc-url https://polygon-bor-rpc.blockreq.com/v1/rpc/public eth_getBlockByHash 0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae false
```

**Hardhat**

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

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

main();
```
