ERC-1175 ERC20 wallet and shop payment standard (Wallet & shop standard for all tokens (erc20))

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

A wallet and shop contract created by WalletCenter that lets payments with an existing ERC20 token be made in a single call instead of two separate calls to approve and transferFrom.

Why it is needed

To buy a product with an ERC20 token, the buyer first had to call approve on the shop address to allow use of the token, and then the shop or an intermediary contract had to call transferFrom again to take the tokens. This required building a new custom payment contract for each token or shop, and created trust issues between two separate transactions and different contracts. ERC-1175 has WalletCenter create wallets and shops directly, so a wallet can immediately verify whether the shop it intends to pay is trustworthy (created by WalletCenter), and bundles approve and transferFrom into a single paySafe call. It also provides shops with standard interface functions for inventory, expiration, and reputation (voting), reducing the need to write new payment logic for each token.

What to implement

In depth

The three-tier WalletCenter, Wallet, Shop structure

The standard is divided into three contracts: WalletCenter, Wallet, and Shop. WalletCenter deploys Wallet and Shop directly via createWallet/createShop, and lets anyone check whether an address was created by it via isWallet/isShop. Wallet acts as a per-user token holding account, and Shop is tied to a single ERC20 token address (_erc20) and sells items. A shop created by WalletCenter is classified as a safe shop.

Reducing payment to a single call

Under the existing ERC20 payment flow, the buyer first allows the shop to spend tokens via approve(_spender,_value), and then the shop or an intermediary calls transferFrom(_from,_to,_value) to take the tokens, requiring two calls. ERC-1175 adds paySafe(_shop,_item) and payUnsafe(_shop,_item) to the Wallet contract so that, with a single call from the owner, the wallet internally looks up the item price, transfers the tokens to the shop, and calls the shop's pay function.

Safe shops and unsafe shops

paySafe has an onlyShop(_shop) condition, so it can only pay shops created by WalletCenter, which are confirmed via WalletCenter.isShop. payUnsafe has no such condition, so it can also pay shop interfaces not created by WalletCenter, but this means there is no guarantee that the shop can be trusted.

Item categories, stock, and expiration

Items registered via Shop's resister(_category,_price,_stock) behave differently depending on the category value. In the Appendix implementation, category 1 can be purchased only once with no stock or expiration, category 2 is a weekly (expiring) model that can be purchased again only after one week has passed since the last purchase, and category 3 is an item whose stock is consumed and can be bought repeatedly in bulk. canBuy and isBuyer are used to look up purchasability and buyer status.

Refunds and payment cancellation

Shop.refund(_buyer,_item,_value) is a function that lets the shop owner return tokens to a buyer, and Wallet.refund is the counterpart function that receives that refund on the wallet side. Wallet.payCancel(_shop,_item) is a function that cancels a payment and receives a refund, available only for weekly-model items.

Shop and item information and reputation

Shop uses info(_msgPack) and infoItem(_item,_msgPack) to store additional shop and item information as msgpack-formatted bytes, announced via the Info/InfoItem events. upVote/dnVote and upVoteItem/dnVoteItem allow casting upvotes and downvotes on shops and items, and about()/aboutItem(_item) let you look up the accumulated upvote/downvote counts.

Proposal status

This proposal was written in June 2018 and is in Stagnant status, with no further discussion ongoing. Note that its content may have changed since or it may never be adopted.

Original ERC · ← ERCs