Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-6932, a proposal to automate access to services that require recurring payments, making it easier for both users and providers to maintain subscriptions.

This article translates, summarizes, and expands on the specification linked below.

I also cover a variety of EIPs, BIPs, SLIPs, CAIPs, ENSIPs, RFCs, and ACPs.

Overview

An ERC subscription token extends an existing ERC20 token (a token standard that defines interfaces for balance management and transfers) with a recurring payment (subscription) mechanism. Like an ordinary ERC20 token, it supports balances and transfers. It also provides the following subscription-specific features.

For an introduction to ERC20, see the article below.

[ERC20] An Introduction to ERC20

  • subscribe / unsubscribe functions These functions let users sign up for or cancel a service subscription. Calling subscribe starts a subscription, while calling unsubscribe stops future recurring charges.

  • subscriptionFee and subscriptionFrequency variables subscriptionFee specifies the subscription fee, and subscriptionFrequency specifies the billing interval (for example, every 30 or 90 days). These variables are stored in the contract and determine how much a user pays and how often the payment becomes due.

  • nextPaymentDate mapping A mapping (a data structure that associates a value with each address) records when each user's next payment is due. For example, if a user subscribes today, the contract records the next payment date for that user's address. Once that time has passed, the token contract uses the recorded information to deduct the fee automatically.

The ERC subscription token aims to allow merchants (service providers) to deduct tokens periodically from users' balances under merchant-defined terms. This provides a mechanism for automated billing for subscription services running on Ethereum.

The benefits for users and merchants include the following.

  • Users no longer need to submit a payment transaction manually every time. Once subscribed, payments take place automatically at the specified intervals.
  • Merchants can implement subscriptions against the token specification rather than building a bespoke mechanism, making the system easier to manage, simpler, and more efficient.

The ERC subscription token also provides a method called renewSubscription. Token holders call this function to renew their subscriptions. It is intended for recurring token-based payments for services and products that require regular billing.

Motivation

Challenges with subscription models

Many services now use subscription business models in which customers pay at regular intervals, such as monthly or annually. Implementing this model on Ethereum, however, often requires users to send a transaction themselves for each payment, which introduces several problems.

  • Users must take action for every payment, creating unnecessary effort.
  • If a user forgets to pay, access to the service may be temporarily interrupted.

The ERC subscription token aims to address this inconvenience and reduce interruptions by providing a standardized mechanism for recurring payments.

Goals of the ERC subscription token

The ERC subscription token allows users to authorize recurring token deductions in advance so that their subscriptions can continue without manual intervention. Users can keep using the service without actively managing payments, while merchants can process recurring charges more reliably.

The token can be used for a wide variety of services requiring recurring payments, including subscription-based content platforms and games. When multiple services implement subscriptions according to the same token specification, their implementations become more consistent and interoperable.

Key features

The ERC subscription token has four main features.

Feature Description
Auto Deduction Merchants define the billing interval and fee for their service. These settings are recorded in the token contract. Once a user subscribes, tokens are automatically deducted from their balance at the specified intervals, without requiring a manually submitted transaction for each payment.
Balance Check Users can check their subscription token balances at any time. Knowing how many tokens remain helps them decide whether to continue a subscription and when to buy additional tokens.
Flexibility The ERC subscription token is intended to support different billing cycles, including monthly, quarterly (every three months), and annual payments. The design also assumes that merchants can define free trials, plan upgrades and downgrades, and cancellation policies, providing a flexible framework for different subscription models.
Security The ERC subscription token uses existing security mechanisms, such as cryptographic signatures (signing transactions with a private key to prove their authenticity), to protect subscription transactions. This is intended to protect both users and merchants from unauthorized access and malicious actions.

Expected benefits

Subscription services can benefit from the ERC subscription token in the following ways.

  • Standardizing recurring payments allows different services to build on the same token specification, improving code reuse and interoperability.
  • Once a user subscribes, subsequent payments are processed automatically, reducing the likelihood of service interruptions.
  • Merchants only need to implement recurring payment logic in accordance with the token specification, reducing the implementation burden while enabling reliable recurring billing.

The ERC subscription token is therefore intended to provide a practical foundation for subscription businesses on Ethereum that is easier for both users and merchants to use.

Specification

Interface

js
interface ISubscriptionERC20 {
  /// @dev map subscribers address, returns address(0) if `idx` is not found
  /// @param idx: the key of the map values
  /// @return the address at key `idx` of subscribers map
  function subscribers(uint idx) external view returns (address);

  /// @dev information of the subscription token contract
  /// @return subscriptionID, subscriptionName, subscriptionDesc, subscriptionTandC
  function subscriptionInfo() external view returns ( uint, string memory, string memory, string memory );

  /// @dev subscribes to the subscription, can be payable
  function subscribe() external;

  /// @dev unsubscribe the subscription
  function unsubscribe() external;

  /// @dev view or pure can be used
  /// @return the subscription fee
  function subscriptionFee() external view returns (uint256);

  /// @dev view or pure can be used
  /// @return get the subscription frequency
  function subscriptionFrequency() external view returns (uint);
}

Functions

subscribers
javascript
function subscribers(uint idx) external view returns (address);

Retrieves the address of a registered subscriber. subscribers returns the address at the specified index in the list of addresses registered for the subscription. Internally, the list is managed as a mapping. If no address exists for idx, the function returns address(0). External callers can use this function to determine which users are registered with the subscription contract.

Parameters

  • idx
    • The numeric key in the address list.

Return value

  • address
    • The registered address associated with the specified key, or address(0) if no entry exists.
subscriptionInfo
javascript
function subscriptionInfo() external view returns (
    uint,
    string memory,
    string memory,
    string memory
);

Retrieves metadata about the subscription. subscriptionInfo is used to obtain the basic subscription information in a single call. The returned values include an identifier, name, description, and terms and conditions. External services and user interfaces can use this function to display subscription details to users.

Return values

  • uint
    • Subscription ID.
  • string
    • Subscription name.
  • string
    • Subscription description.
  • string
    • Subscription terms and conditions.
subscribe
javascript
function subscribe() external;

Registers an address for a subscription. subscribe is called when a user signs up for a subscription service. Internally, the function adds the caller's address to the subscriber list and processes the initial payment if required. An implementation may also make the function payable if it needs to accept payment.

unsubscribe
javascript
function unsubscribe() external;

Cancels an existing subscription. unsubscribe allows users to remove themselves from an active subscription. Once the subscription is canceled, automatic token deductions stop. The function is intended to be called only by a registered subscriber and performs the cancellation internally.

subscriptionFee
javascript
function subscriptionFee() external view returns (uint256);

Retrieves the subscription fee. subscriptionFee returns the fee charged for a single subscription payment. The fee is denominated in tokens and is deducted from the user when subscribing or when a recurring payment becomes due. External applications and user interfaces can call this function to display the fee.

Return value

  • uint256
    • Subscription fee.
subscriptionFrequency
javascript
function subscriptionFrequency() external view returns (uint);

Retrieves the subscription billing interval. subscriptionFrequency returns the interval between payments in seconds. For example, one day is 86400 seconds, and one week is 604800 seconds. Services and user interfaces can use this information to show users when their next payment will be due.

Return value

  • uint
    • Billing interval in seconds.

Additional details

The ERC subscription token incorporates calculation logic to determine recurring payments and deduct the appropriate amount from users' balances. Rather than simply decreasing a balance, it calculates the payment amount based on the time elapsed since a user subscribed and the billing interval.

The following is part of the payment calculation logic.

javascript
uint256 intervals = ( block.timestamp - info.start ) / info.frequency;
uint256 amount = info.amount * intervals;

uint256 localEffectiveBalance = effectiveBalance[account];

if ( (totalAmount + amount) > localEffectiveBalance ) {
    amount = localEffectiveBalance;
}

totalAmount += ( localEffectiveBalance - amount );

How the logic works

The calculation uses the following steps to determine how much should be deducted from a user's balance.

Determine the number of payments from elapsed time

The difference between block.timestamp (the current block timestamp) and info.start (the subscription start time) gives the elapsed time. Dividing that difference by info.frequency (the payment interval) determines how many payment periods have elapsed.

text
intervals = 経過時間 ÷ 支払い間隔

This value is the number of payments. The formula above retains the original Japanese labels: elapsed time divided by the payment interval.

Calculate the payment amount

Multiply the number of payments by info.amount (the fee per payment) to obtain the cumulative payment amount.

text
amount = 一回の支払い額 × 発生した支払い回数

The formula above retains the original Japanese labels: the fee per payment multiplied by the number of payments due.

Check the effective balance of the address (effectiveBalance)

The effective balance is the balance actually available to use, excluding funds already locked for deductions. Unlike the ordinary balanceOf, it is a value specifically intended for processing subscription deductions.

Adjust the payment if it exceeds the balance

If the payment amount exceeds the effective balance, it is capped at the available balance.

Update the final amount to be deducted

The amount to be deducted is accumulated in totalAmount.

This process is intended to handle insufficient user balances safely while deducting the correct amount. The effective balance is also updated whenever a transfer takes place, keeping balance management for subscription payments consistent and automatic.

Security

With the ERC subscription token, users must sign transactions when subscribing, unsubscribing, or performing other important subscription-related operations. Cryptographic signatures are used to establish that the operation was authorized by the user, a fundamental security mechanism in Ethereum.

However, cryptographic signatures require a private key, and if that key is compromised, unauthorized operations become possible. Users should therefore follow the security practices below.

The importance of private key management

A private key proves control over a wallet. If it is compromised, assets may be stolen or subscriptions may be modified without authorization. It is important to store private keys securely and prevent third parties from accessing them.

Using secure wallets

Users who want stronger security can use wallets such as the following.

  • Hardware wallets These manage keys on a physical device, making them resistant to online attacks and keeping the private key inside the device.
  • Secure keystores These store private keys in encrypted form and require a password to decrypt them.

These approaches can significantly reduce the risk of private key theft or unauthorized access.

Protection against social engineering

Phishing and fraudulent websites can trick users into supplying private keys or signatures in the wrong place. Users should always verify the authenticity of the dApp and wallet they are connecting to and carefully evaluate signature requests from unfamiliar websites.

Citation

360 Core hello@360coreinc.com, Robin Rajput (@0xRobinR), "ERC-6932: Subscription-Based Token [DRAFT]," Ethereum Improvement Proposals, no. 6932, April 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6932.

Conclusion

This article covered ERC-6932, a proposal to automate access to services that require recurring payments and make it easier for both users and providers to maintain subscriptions. I hope this explanation was helpful.

If you have questions, feel free to reach out via direct message on Twitter.

Twitter @cardene777

I also publish content on other platforms, which you can find below.