# eth_estimateGas：参数、返回值与 CU

> 原文地址: https://docs.blockvectra.com/zh/api/json-rpc/methods/eth_estimateGas/

## 用途

估算一笔交易执行所需的 gas 上限。

## 计算单位（CU）与价格

CU 权重、价格与各链可用状态见方法页： https://docs.blockvectra.com/zh/api/json-rpc/methods/eth_estimateGas/

## 参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| `transaction` | `object` | 交易调用对象，可包含 from、to、gas、gasPrice、maxFeePerGas、maxPriorityFeePerGas、value、data/input 等字段；它只用于模拟，不会真正改变链上状态，也不消耗 gas。 |
| `blockParameter` | `QUANTITY\|TAG` | 可选，用于估算的区块高度或标签：latest、earliest、pending、safe、finalized；默认按最新区块。 |

## 返回值

- **类型**: `QUANTITY`
- **说明**: 估算出的 gas 数量，0x 十六进制数量。

## 注意事项

估算依据指定区块的状态执行；若该调用会回滚，通常返回错误而不是数值。

## 请求示例

```bash
curl -X POST "https://dev-api.blockvectra.network/v1/robinhood_mainnet" \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: <api_key>' \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_estimateGas",
    "params": [
      {
        "from": "<from>",
        "to": "<to>",
        "data": "<data>"
      },
      "latest"
    ],
    "id": 1
  }'
```
