EIPs Explained

ERC-6932 · Draft · ERC · 2023-04-25

ERC-6932: Subscription-Based Token

A draft ERC-20 extension for recurring payments: a holder subscribes once and the token contract deducts a fixed fee from their balance every period.

What problem does it solve?

Subscriptions are everywhere off-chain, but on Ethereum users usually have to pay manually each period, or grant an open-ended allowance to a merchant contract. Missed payments interrupt service, and big allowances are risky.

ERC-6932 builds the subscription into the ERC-20 token itself. A holder subscribes, and the contract treats a growing slice of their balance as already paid, period after period, until they unsubscribe.

How it works

Each subscription token contract describes one service:

  • subscriptionFee() is the amount charged per period.
  • subscriptionFrequency() is the period length in seconds (e.g. a day, a week, a month).
  • subscriptionInfo() returns an ID, name, description and terms-and-conditions text.
  • subscribers(idx) lists subscribed addresses (returns address(0) past the end).
  • subscribe() and unsubscribe() are called by the holder.

Charging is lazy, not pushed by a keeper. The rationale sketches computing how many full periods have passed since the subscription started and treating fee × periods as locked, capped at the holder's effective balance. A holder's spendable balance is their effective balance minus what ongoing subscriptions have consumed.

intervals = (block.timestamp - start) / frequency
amount    = fee * intervals          // capped at effective balance

Sample code

The interface from the spec:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface ISubscriptionERC20 {
    function subscribers(uint256 idx) external view returns (address);
    function subscriptionInfo() external view returns (uint256, string memory, string memory, string memory);
    function subscribe() external;
    function unsubscribe() external;
    function subscriptionFee() external view returns (uint256);
    function subscriptionFrequency() external view returns (uint256);
}

Checking the cost before subscribing (ethers v6):

const [fee, freq] = await Promise.all([sub.subscriptionFee(), sub.subscriptionFrequency()]);
const perMonth = (fee * 30n * 86400n) / freq;
console.log(`~${formatUnits(perMonth, 18)} tokens per 30 days`);
await (await sub.subscribe()).wait();

Things to know

  • Status is Draft, and the text is loose. The abstract mentions nextPaymentDate and a renewSubscription method that do not appear in the interface, and the accounting formula is only sketched. Expect implementations to differ.
  • Because balances shrink over time without a transaction, balanceOf can change from block to block. Integrations that cache balances or assume they only change on Transfer events may misbehave.
  • One contract equals one subscription service, so the merchant controls the token's charging logic. Read it before subscribing.
  • For subscriptions paid in an existing token, allowance-based or account-abstraction approaches are more common in practice.

#token #erc20 #subscription #payments

Details

Authors
360 Core <[email protected]>, Robin Rajput (@0xRobinR)
Status
Draft
Type
Standards Track / ERC
Created
2023-04-25
Requires

Machine-readable: Markdown · JSON