ERC-1337 · Stagnant · ERC · 2018-08-01
ERC-1337: Subscriptions on the blockchain
A proposed standard for recurring crypto payments in which users sign a subscription once and the merchant later submits that signature to pull each period's payment.
What problem does it solve?
Monthly subscriptions are a core business model on the web, but on Ethereum every payment needs the payer to sign a fresh transaction. Expecting a user to come back each month and send tokens by hand does not work for a SaaS-style product.
ERC-1337 proposes a standard way to do "pull" payments: the user signs the terms of a subscription once, the merchant keeps that signature off-chain, and the merchant (or a relayer) submits it each period to collect payment. The authors compare it to a card-on-file token held by a payment processor.
How it works
The subscriber's contract (the spec has a smart-contract wallet in mind) exposes a small interface and supports ERC-165 interface detection.
- Build the terms.
getSubscriptionHash(recipient, value, data, operation, txGas, dataGas, gasPrice, gasToken, meta)returns a hash of all the parameters together with the contract address.metapacks extra fields such as the period (DAY,WEEK,MONTH) and an optional expiration. - Sign once. The owner signs that hash and hands the signature and inputs to the merchant.
- Collect each period. The merchant calls
executeSubscription(...)with the same inputs plus the signature. The contract checks the signature and that the period has elapsed, then performs the payment (an ETH transfer, an ERC-20 transfer, a call, etc., chosen byoperation). - Manage it.
getSubscriptionStatusreturns the status and the next withdrawal time. The owner can sign a status change (pause, cancel) obtained fromgetModifyStatusHashand submit it viamodifyStatus.
Statuses are ACTIVE, PAUSED, CANCELLED and EXPIRED. The gas fields let the executor be reimbursed for submitting the transaction, optionally in a token.
Sample code
Subscriber side, illustrative (ethers v6). The spec does not fix the exact signature format, so check what your contract verifies:
import { Contract, Wallet, getBytes, ZeroAddress } from "ethers";
const sub = new Contract(SUBSCRIPTION_CONTRACT, [
"function getSubscriptionHash(address,uint256,bytes,uint8,uint256,uint256,uint256,address,bytes) view returns (bytes32)",
], provider);
const ERC20_OP = 3; // Enum.Operation.ERC20
const hash = await sub.getSubscriptionHash(
MERCHANT, 10_000_000n, TOKEN_CALLDATA, ERC20_OP,
100_000n, 0n, 0n, ZeroAddress, META_BYTES,
);
const signature = await owner.signMessage(getBytes(hash));
// send { inputs, signature } to the merchant, who later calls executeSubscription(...)
Things to know
- Status: Stagnant. Sections such as Test Cases and Implementation are still marked TBD, and some function signatures in the spec are incomplete (for example a missing comma), so it is not implementable verbatim.
- As the spec itself notes, a signed subscription remains executable unless its hash is recorded on-chain and its status changed. Cancelling means submitting a signed status change, not just stopping off-chain.
- Today, recurring and delegated payments are more often built with smart accounts and session keys or with token allowances plus signed approvals such as ERC-2612, rather than with this interface.