---
title: "eth_getTransactionByBlockHashAndIndex"
description: "按区块哈希和索引返回交易（BSC）"
url: "https://blockreq.com/docs/zh-cn/build/api-reference/bsc/eth_getTransactionByBlockHashAndIndex/"
---

# eth_getTransactionByBlockHashAndIndex

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

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

## 描述

按区块哈希和索引返回交易。

## 参数

| 参数        | 类型  | 必填 | 说明                 |
| ----------- | ----- | ---- | -------------------- |
| `blockHash` | `hex` | 是   | 区块哈希             |
| `index`     | `hex` | 是   | 交易索引（十六进制） |

## 请求

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getTransactionByBlockHashAndIndex",
  "params": ["0x...", "0x0"],
  "id": 1
}
```

## 代码示例

**cURL**

```bash
curl -X POST https://bsc-rpc.blockreq.com/v1/rpc/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0x...","0x0"],"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_getTransactionByBlockHashAndIndex",
  "params": [
    "0x...",
    "0x0"
  ],
  "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_getTransactionByBlockHashAndIndex",
  "params": [
    "0x...",
    "0x0"
  ],
  "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_getTransactionByBlockHashAndIndex","params":["0x...","0x0"],"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_getTransactionByBlockHashAndIndex",
  params: ["0x...","0x0"],
});
console.log(result);
```

**Foundry**

```bash
cast rpc --rpc-url https://bsc-rpc.blockreq.com/v1/rpc/public eth_getTransactionByBlockHashAndIndex 0x... 0x0
```

**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_getTransactionByBlockHashAndIndex", ["0x...","0x0"]);
  console.log(result);
}

main();
```
