---
eip: 1474
label: EIP-1474
title: Remote procedure call specification
status: Stagnant
type: Standards Track
category: Interface
created: 2018-10-02
official: https://eips.ethereum.org/EIPS/eip-1474
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1474.md
canonical: https://eips.huatuo.xyz/zh/eip-1474/
lang: zh
tldr: 尝试为以太坊节点编写一份统一的正式 JSON-RPC 规范（方法、值编码和错误码），使 dapp 在每个客户端上都获得相同的行为。
tags: [json-rpc, api, nodes, interface]
---

# EIP-1474: Remote procedure call specification

> This proposal defines a standard set of remote procedure call methods that an Ethereum node should implement.

**TL;DR:** 尝试为以太坊节点编写一份统一的正式 JSON-RPC 规范（方法、值编码和错误码），使 dapp 在每个客户端上都获得相同的行为。

## 它解决什么问题？

钱包、库和 dapp 通过 JSON-RPC（`eth_getBalance`、`eth_call`、`eth_sendRawTransaction` 等）与以太坊节点通信。2018 年时，这些方法没有正式规范，只有客户端文档和一个 wiki 页面。各客户端在方法签名、编码和错误行为上各不相同，因此应用不得不绕开每个节点的怪癖。

EIP-1474 把这些方法汇总到一份文档中，并使其可以通过正常的 EIP 流程进行修改。

## 它如何运作

该提案定义了三层：

- **传输。** 每次调用都是一个 JSON-RPC 2.0 请求对象，并且必须得到一个 JSON-RPC 2.0 响应对象。
- **值编码。**
  - `Quantity`（数字）：以 `0x` 为前缀的十六进制，无前导零；零是 `0x0`。因此 `0x400` 有效，而 `0x0400` 无效。
  - `Data`（字节）：以 `0x` 为前缀的十六进制，每字节两位数字。`0x` 是空数据，`0x00` 是一个零字节。
  - 区块参数可以是区块号、`latest` 之类的标签，或者（依据 [EIP-1898](/eip-1898/)）一个对象 `{ blockHash, requireCanonical }`。
- **错误。** 除标准的 JSON-RPC 错误码（`-32700` 至 `-32603`）外，它还保留了以太坊专用的错误码，例如 `-32000` 表示输入无效、`-32001` 表示资源未找到、`-32003` 表示交易被拒绝、`-32004` 表示不支持该方法、`-32005` 表示超出限制。

随后它记录了每个方法的参数、返回值和一个示例：`web3_*`、`net_*` 以及 `eth_*` 系列，包括区块、交易、收据、日志和过滤器、`eth_call`、`eth_estimateGas`、签名，以及旧的挖矿方法。

## 示例代码

按规范格式书写的原始请求：

```sh
curl -X POST -H "Content-Type: application/json" --data '{
  "id": 1, "jsonrpc": "2.0",
  "method": "eth_getBalance",
  "params": ["0x0000000000000000000000000000000000000000", "latest"]
}' "$RPC_URL"
# -> {"id":1,"jsonrpc":"2.0","result":"0x..."}   (a Quantity, in wei)
```

通过 ethers v6 进行的同一调用，编码由它替你处理：

```ts
import { JsonRpcProvider, toQuantity } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const hex = await provider.send("eth_getBalance", [someAddress, "latest"]);
console.log(BigInt(hex));          // decode Quantity
console.log(toQuantity(1024));     // "0x400" - encode, no leading zeros
```

## 需要注意

- 状态为 **Stagnant**。节点 API 现行的权威参考是由社区维护的以太坊 execution-apis 规范（基于 OpenRPC），而不是这份 EIP。[EIP-1901](/eip-1901/) 提出了采用 OpenRPC 的 `rpc.discover` 方案。
- 这里列出的一些方法在当今的网络上已经过时，尤其是工作量证明的挖矿调用（`eth_getWork`、`eth_submitWork`、`eth_hashrate`）和叔块查询。
- `-32603` 之外的错误码至今仍未被所有客户端一致使用，因此在未针对你的提供方测试之前，不要依赖确切的错误码来控制流程。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1474
