---
eip: 1438
label: ERC-1438
title: dApp Components (avatar) & Universal Wallet
status: Stagnant
type: Standards Track
category: ERC
created: 2018-09-21
official: https://eips.ethereum.org/EIPS/eip-1438
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-1438.md
canonical: https://eips.huatuo.xyz/zh/eip-1438/
lang: zh
tldr: "一个已停滞的提案，涉及可复用的 dApp 组件、链上头像商店，以及一个基于合约的\"通用钱包\"，可以一次调用就向任何接受 ERC-20 的服务付款，即使代币没有 approveAndCall 也可以。"
tags: [wallet, erc20, avatar, components, stagnant]
---

# ERC-1438: dApp Components (avatar) & Universal Wallet

> Contracts are open source based. And most developers use the public contracts at the start of the project to modify or simply include them. This is project-oriented centralized development and I think it is a waste of resources.

**TL;DR:** 一个已停滞的提案，涉及可复用的 dApp 组件、链上头像商店，以及一个基于合约的"通用钱包"，可以一次调用就向任何接受 ERC-20 的服务付款，即使代币没有 approveAndCall 也可以。

## 它解决什么问题？

作者观察到，大多数项目把开源合约复制到自己孤立的 dApp 中，因此每个 dApp 产生的数据都被锁在其内部。该提案认为链上资源应当能在各服务之间复用，并给出了两个"组件 dApp"的例子：

1. **头像商店**：用户只需创建一次头像，其他任何服务都可以显示它。
2. **通用钱包**：用 [ERC-20](/eip-20/) 代币向服务付款通常需要两笔交易（先 `approve`，再由服务调用 `transferFrom`）。一些代币增加了 `approveAndCall` 以便一步完成，但大多数已部署的 ERC-20 并不支持。钱包合约可以为*任何* ERC-20 提供同样的一步式体验。

## 它如何运作

**头像。** 商店针对选定的 ERC-20 货币创建，带有可配置的资源类别和一个查看器脚本。头像资源是 gzip 压缩的 SVG，头像数据是 msgpack 编码的 JSON，两者都存放在事件日志而非合约存储中，以降低成本。

**通用钱包。** 每个用户部署一个持有 ETH 和代币的钱包合约：

- `balanceOf(erc20)`、`transfer(erc20, to, amount)`、`approve(erc20, spender, amount)`，其中 `address(0)` 表示 ETH。
- `pay(store, amount, options)`：查询商店想要哪种代币和哪个 spender，进行授权（或发送 ETH），然后立即调用商店的 `receiveApproval(...)`。从用户的角度看，授权和使用发生在同一笔交易中。

商店实现一个 `ApproveAndCallFallBack` 风格的接口，暴露 `erc20()`、`spender()` 和 `receiveApproval(...)`。

## 示例代码

钱包所模拟的 `approveAndCall` 模式，以及接收它的商店（现代 Solidity，已简化）：

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IERC20 {
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

interface IStore {
    function erc20() external view returns (address);
    function spender() external view returns (address);
    function receiveApproval(uint256[] calldata options) external;
}

contract UniversalWallet {
    address public immutable owner;
    constructor() { owner = msg.sender; }

    /// Approve and notify the store in one transaction.
    function pay(IStore store, uint256 amount, uint256[] calldata options) external {
        require(msg.sender == owner, "owner only");
        IERC20(store.erc20()).approve(store.spender(), amount);
        store.receiveApproval(options); // store pulls funds with transferFrom
    }
}
```

## 需要注意

- 状态为 **Stagnant**。参考代码面向 Solidity 0.4，并使用了 EIP 中未规定的 `onlyOwner` 基础合约。
- 在参考实现的 `pay` 中，商店的 `receiveApproval` 并不知道涉及哪个钱包或金额；真实的商店必须安全地跟踪这一点（例如使用 `msg.sender` 并检查 allowance）。
- 单笔交易完成付款的问题后来由 [ERC-1363](/eip-1363/)（`transferAndCall` / `approveAndCall`）等标准和 permit 风格的签名解决，如今则由批量调用的智能合约账户解决。
- 把数据存进事件日志很便宜，但日志无法被合约读取，只能在链下读取。


---

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