EIPs Explained

ERC-1175 · Stagnant · ERC · 2018-06-21

ERC-1175: Wallet & shop standard for all tokens (erc20)

A proposed set of wallet, shop and registry contracts that would let users buy items with any ERC-20 token in a single call instead of the usual approve-then-transferFrom dance.

What problem does it solve?

Paying a merchant contract with an ERC-20 token normally takes two transactions: the buyer calls approve on the token, then the shop calls transferFrom to pull the funds. Every shop also has to write its own payment logic for every token it accepts.

ERC-1175 proposes a shared framework so that a user's wallet contract and a merchant's shop contract can trust each other. Once both exist, a purchase is one call from the wallet owner: paySafe(shop, item).

How it works

There are three kinds of contract:

Contract Role
WalletCenter Factory and registry. createWallet() and createShop(erc20) deploy new instances; isWallet / isShop tell whether an address was created by it.
Wallet Owned by a user. Holds ETH and tokens, and pays shops with paySafe, payUnsafe or cancels with payCancel. withdrawal returns funds to the owner.
Shop Owned by a merchant and tied to one ERC-20 token (or ETH). Lists items with resister(category, price, stock), quotes with price(item), and accepts pay(item) only from registered wallets.

A shop created by the WalletCenter is a safe shop. paySafe only works for safe shops; payUnsafe lets a wallet pay a shop that merely reuses the interface.

During a payment the wallet looks up the item's token and price, approves the shop for that amount, and calls shop.pay(item). The shop checks that the caller is a registered wallet and pulls the tokens. Because the wallet contract performs both steps internally, the user only signs one transaction.

The reference code defines item categories: one-time purchases, items that expire after a week (with cancellation and refund), and stackable items with a stock count. Shops and items also carry free-form info bytes and up/down vote counters.

Sample code

Paying a safe shop from a user's wallet contract with ethers v6 (addresses are placeholders):

import { Contract, Wallet, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const owner = new Wallet(process.env.PRIVATE_KEY!, provider);

const center = new Contract(CENTER_ADDRESS, [
  "function isShop(address) view returns (bool)",
], provider);

const wallet = new Contract(MY_WALLET_ADDRESS, [
  "function paySafe(address shop, uint256 item) payable returns (bool)",
], owner);

const shop = new Contract(SHOP_ADDRESS, [
  "function price(uint256 item) view returns (address erc20, uint256 value)",
  "function canBuy(address who, uint256 item) view returns (bool)",
], provider);

const item = 0n;
if (await center.isShop(SHOP_ADDRESS) && await shop.canBuy(MY_WALLET_ADDRESS, item)) {
  const [token, value] = await shop.price(item);
  console.log(`item costs ${value} of token ${token}`);
  await (await wallet.paySafe(SHOP_ADDRESS, item)).wait(); // one transaction
}

Things to know

  • Status: Stagnant. The proposal never gained adoption and there is no widely used implementation.
  • The reference code targets Solidity 0.4.24 (constant, now, .transfer) and will not compile on modern compilers without changes. It has not been audited; treat it as a sketch.
  • Funds must sit in a per-user wallet contract rather than the user's own address, which is the main trade-off versus simply calling approve and transferFrom.
  • Several method names in the spec are unusual (resister for "register", dnVote for "down vote"); keep the spelling exact if you implement against it.
  • Today, single-transaction token payments are more commonly achieved with signature-based approvals such as ERC-2612 permit.

#token #payments #commerce #erc20 #wallet

Details

Authors
Jet Lim (@Nitro888)
Status
Stagnant
Type
Standards Track / ERC
Created
2018-06-21
Requires

Machine-readable: Markdown · JSON