---
eip: 107
label: EIP-107
title: "safe \"eth_sendTransaction\" authorization via html popup"
status: Stagnant
type: Standards Track
category: Interface
created: 2016-06-05
official: https://eips.ethereum.org/EIPS/eip-107
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-107.md
canonical: https://eips.huatuo.xyz/zh/eip-107/
lang: zh
tldr: 2016 年的一项提案：由节点提供 HTML 弹窗，使普通网站无需启用 CORS 并信任 dapp，就能在用户确认后请求 eth_sendTransaction。
tags: [json-rpc, wallet, dapp, authorization, interface]
---

# EIP-107: safe "eth_sendTransaction" authorization via html popup

> This draft EIP describes the details of an authorization method that if provided by rpc enabled ethereum nodes would allow regular websites to send transactions (via ethsendTransaction) without the need to enable CORS. Instead, user would be asked to confirm the transaction via an html popup.

**TL;DR:** 2016 年的一项提案：由节点提供 HTML 弹窗，使普通网站无需启用 CORS 并信任 dapp，就能在用户确认后请求 eth_sendTransaction。

## 它解决什么问题？

2016 年时，普通浏览器中的 dapp 只有在你为其域名启用 CORS 后，才能访问本地以太坊节点的 RPC。一旦启用，该网站就可以不经任何提示，从任何**已解锁**的账户调用 `eth_sendTransaction`。用户要么完全信任该网站，要么手动把交易复制到 Mist 或节点控制台中。

EIP-107 提出了一种让网站安全使用节点的方法：只读调用可以直接使用，而每笔交易都需要用户明确点击确认。

## 它如何运作

节点在 `<node url>/authorization.html` 提供一个自包含的页面。由于该页面来自节点自己的源，浏览器的同源策略会对其提供保护。dapp 以两种方式使用该页面：

1. **不可见的 iframe。** dapp 嵌入该页面，并通过 `window.postMessage` 发送只读 RPC 调用。iframe 会拒绝任何需要已解锁密钥的调用，因此隐藏的框架无法诱骗用户确认。
2. **弹出窗口。** 对于 `eth_sendTransaction`，dapp 在新窗口中打开同一 URL。窗口会显示发送方、接收方、金额和 gas 费用，只有用户确认后才会转发调用。`eth_sign` 被有意禁止，因为弹窗无法安全地展示其含义。

消息协议：

- 框架或窗口首先发送字符串 `"ready"`。
- dapp 发送 `{ id, payload }`，其中 `payload` 是普通的 JSON-RPC 对象。
- 回复为 `{ id, result, error }`，`error.type === "cancel"` 表示用户拒绝。
- 必须设置 `from`、`gas` 和 `gasPrice`，以便弹窗显示它们。

如果账户已锁定且节点公开了 `personal` API，弹窗可以请求输入密码并短暂解锁账户（参考页面中为 3 秒）。

## 示例代码

dapp 一侧，通过弹窗发送交易：

```ts
const NODE = "http://localhost:8545";
const popup = window.open(`${NODE}/authorization.html`, "eth-auth", "width=420,height=520")!;

window.addEventListener("message", (ev) => {
  if (ev.origin !== NODE) return;
  if (ev.data === "ready") {
    popup.postMessage({
      id: 1,
      payload: {
        jsonrpc: "2.0", id: 1, method: "eth_sendTransaction",
        params: [{ from: "0x…", to: "0x…", value: "0x2386f26fc10000",
                   gas: "0x5208", gasPrice: "0x4a817c800" }],
      },
    }, NODE);
  } else if (ev.data.id === 1) {
    if (ev.data.error?.type === "cancel") console.log("user rejected");
    else console.log("tx hash", ev.data.result);
  }
});
```

## 需要注意

- 该提案处于 **Stagnant** 状态，从未被标准化，也未被广泛部署。
- 生态系统走了另一条路。浏览器扩展等钱包会注入提供者（[EIP-1193](/eip-1193/)），请求用户连接账户（[EIP-1102](/eip-1102/)、[EIP-2255](/eip-2255/)），并显示自己的确认界面。如今节点通常根本看不到用户的密钥。
- 该设计假定账户在节点内部解锁，而这种做法现在已不被提倡。
- 它仍然是一份有价值的历史记录，说明了"dapp 绝不能在没有用户参与的情况下签名"为何成为钱包的核心原则。


---

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