ERC-1337 On-chain Recurring Payment Signature Standard (Subscriptions on the blockchain)

Stagnant · Signatures & auth · created 2018-08-01

A subscription payment standard in which a user signs payment terms once, and a merchant can later submit that signature so the contract automatically executes the recurring payment.

Why it is needed

On the web, subscription payments are common, where a credit card token is stored with a payment processor and charges are billed automatically every month, but Ethereum had no standardized way to handle this kind of recurring payment. If users had to send a transaction manually every month, it would be difficult to run subscription services or SaaS business models on the blockchain. Also, if each service implemented its recurring payment logic differently, wallets and contracts would be incompatible with each other, fragmenting the ecosystem. ERC-1337 addresses this by proposing a common specification in which a user signs payment terms data once, the merchant stores it off-chain, and submits it to the contract whenever needed to execute the payment.

What to implement

In depth

Signature-based reusable transactions

getSubscriptionHash bundles recipient, value, data, operation (Enum.Operation: Call/DelegateCall/Create/ERC20/ERC20Approve), txGas, dataGas, gasPrice, gasToken, and meta into a hash. The user signs this hash once, and the signature then behaves like a check. Unless the hash is separately recorded on-chain, a valid signature remains executable later as well, so changing its state requires explicitly capturing it via modifyStatus.

The subscription status enum

Enum.SubscriptionStatus has four values, ACTIVE, PAUSED, CANCELLED, and EXPIRED, and getSubscriptionStatus returns the current status along with the next withdrawal time (nextWithdraw). Enum.Period represents the payment period as INIT, DAY, WEEK, or MONTH.

modifyStatus and getModifyStatusHash

To change a subscription's status, the user signs a hash created by getModifyStatusHash (combining the subscriptionHash with the desired Enum.SubscriptionStatus) and submits that signature to modifyStatus. This process can pause, cancel, or expire an active subscription.

The gas reimbursement structure of executeSubscription

In addition to to, value, data, and operation, executeSubscription takes txGas, dataGas, gasPrice, and gasToken. If gasToken is address(0), gas costs are reimbursed in ETH; otherwise they are reimbursed in the specified token, and this only works in escrow implementations. The source specifies that even if execution fails, the party that submitted the transaction is still paid the gas fee.

The meta field

meta is a dynamic byte array with 4 slots, 2 required and 2 optional: refundAddress, period, offChainID, and expiration (a Unix timestamp). This field jointly encodes the refund address, payment period, off-chain identifier, and subscription expiration time.

Relationship to ERC-165 and ERC-20

This standard specifies ERC-165 (for querying interface support) and ERC-20 as requirements. Enum.Operation includes ERC20 and ERC20Approve values, so the type of call can be specified not only as a plain Call/DelegateCall/Create but also as an ERC-20 token transfer or approval.

Similarity to credit card tokenization

The source Rationale compares this structure to how a credit card merchant stores a token received from a payment processor and later draws funds from the customer's card. The flow in which a merchant stores a hash signed by the user along with the inputs that produced it, then submits it to the subscription contract, plays the same role.

Proposal status

This proposal is in Stagnant status. Written in August 2018, with Test Cases and Implementation still marked TBD, it is no longer being actively discussed. It may be changed or may never be adopted.

Original ERC · ← ERCs