---
title: "eth_getBalance"
description: "返回账户余额（Ethereum）"
url: "https://blockreq.com/docs/zh-cn/build/api-reference/ethereum/eth_getBalance/"
---

# eth_getBalance

**网络：** Ethereum · 主网 · Chain ID `1`（`0x1`）

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

返回指定地址账户余额。

## 参数

1. `DATA`（20 字节）— 要查询余额的地址。
2. `QUANTITY|TAG` — 区块号，或 `"latest"`、`"earliest"`、`"pending"`。

## 返回

`QUANTITY` — 当前余额（单位 wei）。

## 请求

```json
{
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": ["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "latest"],
  "id": 1
}
```

## 响应

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x6c6b935b8bbd400000"
}
```

> 返回值单位为 **wei**。`0x6c6b935b8bbd400000` = 2000 × 10^18 wei，即 2,000 个 Ethereum 原生代币。

## 代码示例

**cURL**

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

**TypeScript**

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

**Python**

```python
import requests

response = requests.post(
    "https://ethereum-rpc.blockreq.com/v1/rpc/public",
    json={
  "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": [
    "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
    "latest"
  ],
  "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_getBalance","params":["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","latest"],"id":1}`)
	resp, err := http.Post(
		"https://ethereum-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://ethereum-rpc.blockreq.com/v1/rpc/public"),
});

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

**Foundry**

```bash
cast rpc --rpc-url https://ethereum-rpc.blockreq.com/v1/rpc/public eth_getBalance 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 latest
```

**Hardhat**

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

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

main();
```
