ERC-1438 Avatar component and universal wallet (dApp Components (avatar) & Universal Wallet)

Stagnant · Accounts & wallets · created 2018-09-21

A proposal that stores avatar and social badge information on the blockchain so it can be reused across multiple dApps, and that lets a single wallet query, transfer, approve, and pay with both ETH and ERC20 tokens.

Why it is needed

Most Ethereum dApps are developed by copying open source contracts as-is and attaching them to each individual project. Information such as avatars and social badges created this way is locked inside that dApp, cannot be reused by other services, and the same functionality ends up being rebuilt from scratch for each service, wasting resources. In addition, although there are many ERC20 tokens, many of them do not support an approveAndCall method that handles approval and execution in a single step, which makes it hard for wallets or payment services to handle ETH and multiple ERC20 tokens in a unified way. To reduce this fragmentation, this proposal presents a reusable avatar component and a universal wallet that handles ERC20 and ETH together.

What to implement

In depth

Avatar store (1.1)

An avatar store is created after the ERC20 currency has first been set. Operators can customize both the categories of assets used for avatars and the viewer script that renders those assets on screen. In other words, each store is free to decide what kinds of avatar parts it sells and how they are displayed.

Asset and user data storage (1.2)

An avatar's assets and user information are stored not in contract state but in the event log portion of the blockchain. Assets are created in SVG format and compressed with gzip, and avatar information is recorded as JSON data compressed with msgpack. Leaving this in the event log means other dApps can also read the same log to fetch and reuse the avatar assets and information.

Standard ERC20 interface (2.1)

ERC20Interface is the conventional ERC20 interface, consisting of the six functions totalSupply, balanceOf, allowance, transfer, approve, and transferFrom, plus the two events Transfer and Approval. UniversalWallet communicates with each token contract through this interface.

approveAndCall and its limitations (2.2, 2.3)

Some ERC20 contracts additionally provide an approveAndCall(spender, tokens, data) function that handles approval and a function call in a single transaction. This function sets the approval value, emits an Approval event, and then immediately calls receiveApproval on the specified spender contract. However, the source text points out that not many ERC20 tokens implement approveAndCall this way. On the spender side, receiveApproval(from, tokens, token, data) from the ApproveAndCallFallBack interface is implemented to receive the approval notification.

UniversalWallet's lookup, transfer, and approval (2.4)

In its balanceOf, transfer, and approve functions, UniversalWallet branches to operate on ETH if the _erc20 address passed in is 0, and on that ERC20 token otherwise. balanceOf can be called by anyone, but transfer and approve carry an onlyOwner restriction, so only the wallet owner can execute them. transfer checks via balanceOf that the balance is sufficient before executing.

Processing payment requests via the pay function (2.4)

The pay function is overloaded in two versions: one that takes uint256[] _options and one that takes bytes _msgPack. Both look up the erc20 and spender addresses from the target _store contract for payment, then transfer ETH if erc20 is 0 or approve that token to the spender otherwise. They then call the _store's receiveApproval along with _options or _msgPack, handing payment processing off to the store. Both functions are restricted with onlyOwner.

Proposal status

This ERC is in Stagnant status, a proposal that is no longer actively discussed and has stalled. Since it has not been finalized as a standard, the interface described here cannot be considered as having been adopted as is.

Original ERC · ← ERCs