---
title: "eth_getLogs"
description: "返回符合过滤条件的日志（Arc）"
url: "https://blockreq.com/docs/zh-cn/build/api-reference/arc/eth_getLogs/"
---

# eth_getLogs

**网络：** Arc · 主网 · Chain ID `5042`（`0x13b2`）

**数据：** 全节点。Arc 不提供旧区块状态，请查询近期区块。

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

返回与过滤器对象匹配的日志数组。这是索引和监听合约事件时最常用的方法之一。

## 参数

1. `Object` — 过滤配置：
   | 字段 | 类型 | 说明 |
   |-------|------|-------------|
   | fromBlock | QUANTITY\|TAG | 起始区块（默认 `"latest"`） |
   | toBlock | QUANTITY\|TAG | 结束区块（默认 `"latest"`） |
   | address | DATA\|Array | 要过滤的合约地址 |
   | topics | Array | Topic 过滤条件（事件索引参数） |
   | blockHash | DATA | 限定单个区块 |

## 返回

`Array` — 日志对象数组：

| 字段            | 类型          | 说明               |
| --------------- | ------------- | ------------------ |
| address         | DATA          | 产生日志的合约地址 |
| topics          | `Array<DATA>` | 已索引事件参数     |
| data            | DATA          | 未索引事件参数     |
| blockNumber     | QUANTITY      | 区块号             |
| transactionHash | DATA          | 交易哈希           |
| logIndex        | QUANTITY      | 区块内日志索引     |

## 请求

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "0x134E800",
      "toBlock": "0x134E810",
      "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]
    }
  ],
  "id": 1
}
```

示例过滤单个代币合约的 ERC-20 `Transfer` 事件。请把 `address` 和区块范围换成 Arc 上的值。

> Topic `0xddf252ad...` 是 `Transfer(address,address,uint256)` 的 keccak-256 哈希。

## 代码示例

**cURL**

```bash
curl -X POST https://arc-rpc.blockreq.com/v1/rpc/public \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock":"0x134E800","toBlock":"0x134E810","address":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],"id":1}'
```

**TypeScript**

```typescript
const response = await fetch("https://arc-rpc.blockreq.com/v1/rpc/public", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
  "jsonrpc": "2.0",
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "0x134E800",
      "toBlock": "0x134E810",
      "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
      ]
    }
  ],
  "id": 1
}),
});
const data = await response.json();
console.log(data.result);
```

**Python**

```python
import requests

response = requests.post(
    "https://arc-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_getLogs",
  "params": [
    {
      "fromBlock": "0x134E800",
      "toBlock": "0x134E810",
      "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
      "topics": [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
      ]
    }
  ],
  "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_getLogs","params":[{"fromBlock":"0x134E800","toBlock":"0x134E810","address":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],"id":1}`)
	resp, err := http.Post(
		"https://arc-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://arc-rpc.blockreq.com/v1/rpc/public"),
});

const result = await client.request({
  method: "eth_getLogs",
  params: [{"fromBlock":"0x134E800","toBlock":"0x134E810","address":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}],
});
console.log(result);
```

**Foundry**

```bash
cast rpc --rpc-url https://arc-rpc.blockreq.com/v1/rpc/public eth_getLogs {"fromBlock":"0x134E800","toBlock":"0x134E810","address":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}
```

**Hardhat**

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

async function main() {
  const provider = new ethers.JsonRpcProvider("https://arc-rpc.blockreq.com/v1/rpc/public");
  const result = await provider.send("eth_getLogs", [{"fromBlock":"0x134E800","toBlock":"0x134E810","address":"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"]}]);
  console.log(result);
}

main();
```
