ERC-1438 · Stagnant · ERC · 2018-09-21
ERC-1438: dApp Components (avatar) & Universal Wallet
A stagnant proposal for reusable dApp components, an on-chain avatar shop and a contract-based 'universal wallet' that pays any ERC-20-accepting service in one call, even tokens without approveAndCall.
What problem does it solve?
The author observed that most projects copy open-source contracts into their own isolated dApps, so the data each dApp produces is locked inside it. The proposal argues that on-chain resources should be reusable across services, and gives two example "component dApps":
- Avatar shop: users create an avatar once and any other service can display it.
- Universal wallet: paying a service with an ERC-20 token normally takes two transactions (
approve, then the service callstransferFrom). Some tokens addapproveAndCallto do it in one step, but most deployed ERC-20s do not. A wallet contract can provide the same one-step experience for any ERC-20.
How it works
Avatar. A shop is created for a chosen ERC-20 currency with configurable asset categories and a viewer script. Avatar assets are gzip-compressed SVG and avatar data is msgpack-encoded JSON, both stored in event logs rather than contract storage to keep costs down.
Universal wallet. Each user deploys a wallet contract that holds ETH and tokens:
balanceOf(erc20),transfer(erc20, to, amount),approve(erc20, spender, amount), withaddress(0)meaning ETH.pay(store, amount, options): looks up which token and spender the store wants, approves (or sends ETH), then immediately calls the store'sreceiveApproval(...). Approval and use happen in one transaction from the user's point of view.
Stores implement an ApproveAndCallFallBack-style interface exposing erc20(), spender() and receiveApproval(...).
Sample code
The approveAndCall pattern the wallet emulates, and a store that receives it (modern Solidity, simplified):
// 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
}
}
Things to know
- Status is Stagnant. The reference code targets Solidity 0.4 and uses an
onlyOwnerbase contract that is not specified in the EIP. - In the reference
pay, the store'sreceiveApprovalis not told which wallet or amount is involved; a real store must track that safely (e.g. usemsg.senderand check allowances). - The one-transaction payment problem was later addressed by standards such as ERC-1363 (
transferAndCall/approveAndCall) and by permit-style signatures, and today by smart-contract accounts that batch calls. - Storing data in event logs is cheap, but logs cannot be read by contracts, only off-chain.