Recurring payments on the blockchain have been a topic of discussion for some time. First introduced in EIP-1337 in 2018, the proposal never really caught on. My approach to recurring payments on Ethereum takes a simpler approach than EIP-1337 did, which may help it have a larger impact on the community.
The full source for this PoC can be found within the Jon-Becker/Ethereum-Recurring-Payments GitHub repository. The repository version I will reference in this write-up is
The recurring payment implementation I will explore throughout this paper is an application of the ERC-20 Token Standard's
approve(...) function. An unlimited allowance (
2^256-1) is approved to the subscription contract address, which periodically allows the
_payee to call a timelocked proxy of ERC-20's
_spendermust only call 2 transactions to create a subscription;
createSubscription(...).The burden is on the payee to call the
transferFrom(...)proxy, meaning they must pay the gas fees to process future payments.
_spenderapproves at least enough to pay for a minimum of 2 transactions. Although unlimited approvals of ERC-20 tokens are against Solidity best practice, this PoC allows for recurring payments on Ethereum in a generally secure manner, where the only potential losses lie in the smart contract's integrity.
block.timestampfor the timelock. This is generally not an issue, but should be noted.
Returns the Subscription of
function getSubscription(address _customer, address _payee) public view returns(Subscription memory)
Returns the time in seconds remaining until the subscription payment may be charged again.
function subscriptionTimeRemaining(address _customer, address _payee) public view returns(uint256)
Creates a Subscription which allows
_payee to charge the caller
_subscriptionPeriod, until the Subscription is cancelled.
This may only be called by the customer, and will automatically charge them for the first billing period. Requires an approval to the subscription contract address of
_subscriptionCost * 2.
function createSubscription(address _payee, uint256 _subscriptionCost, address _token, string memory _name, string memory _description, uint256 _subscriptionPeriod ) public virtual
Cancels a subscription between
_payee and disallows further
This can be called by either party.
function cancelSubscription(address _customer, address _payee ) public virtual
_customer for the subscription between
_customer and the payee a total of
_subscriptionCost, given that they have enough token balance and
This must be called by the payee.
function executePayment(address _customer) public virtual
An internal function that returns
true if the subscription between
_payee has been paid for the current period, or
false if otherwise.
function _subscriptionPaid(address _customer, address _payee) internal view returns(bool)
MUST be called whenever a new subscription is created.
event NewSubscription(Customer, Payee, Allowance, TokenAddress, Name, Description, LastExecutionDate, SubscriptionPeriod);
MUST be called whenever a new subscription is cancelled.
event SubscriptionCancelled(Customer, Payee);
MUST be called whenever a new subscription is paid.
event SubscriptionPaid(Customer, Payee, PaymentDate, PaymentAmount, NextPaymentDate);
This method of allowing smart-contracts to recursively call
transferFrom(...) based on an timelocked proxy function enables subscriptions on the blockchain, one of the most important aspects when it comes to running a service or business. The approach this PoC takes is also trustless, and can be revoked any time by the owner, allowing for a truly decentralized form of recurring payments & subscriptions on Ethereum.