Recurring payments on ethereum


Implementing recurring payments on Ethereum (Post) is not as easy as I thought it'd be. It's hard because only EOAs "Externally Owned Accounts" (humans) can create transactions. In ethereum, a "transaction" is any action from an EOA that changes the state of the ethereum network. Sending ether from one person to another is the simplest form of a transaction. The more complicated form of a transaction is when an EOA sends a transaction to a CA "Contract Account". A CA or "smart contract" is basically a computer program that runs on the ethereum blockchain. An example is the smart contract I have for Pethreon. Pethreon is a dapp "decentralized application" that lets users make payments to each other on a regular interval. You might be wondering, if a CA can't initiate a transaction, how does Pethreon pay people at a regular interval?

There's a few ways people have done this. One way is to evaluate transactions "eagerly" and another way is to evaluate transactions "lazily". To build my Pethreon dapp, I relied on Sergei's smart contract which evaluated transactions lazily. What does that mean? Basically, my pethreon dapp is not actually paying people on a regular interval at all. What happens is, whenever someone tries to collect the money given to them from my dapp, they are forced to visit the application and create a withdrawal transaction. This transaction then tallies up all the money that is owed to them and pays them out. It's "lazy" in the sense that all the payment processing stuff is pushed to the very end when someone tries to cash out.

There's some downsides to this. If the person doesn't know about the app, they can't get paid because they must visit the app to cash out. This is different from a normal transaction on ethereum, where you can just pay someone and the money shows up in their wallet automatically. The person also has to pay a bit of money to cash out, because they have to create a transaction which does all the work. So how could we evaluate the transactions "eagerly"?

To evaluate transaction's eagerly, I would need to use a decentralized service like Ethereum Alarm Clock. This is when my dapp pays EOAs (strangers) to create transactions at regular intervals. Those transactions would then immediately cash out money to people's wallets. This has several advantages. The person receiving the payment would no longer have to know about my app and they would receive regular payments. The person receiving payment wouldn't have to pay for the withdraw function either. The downside is the alarm clock service costs money and can be difficult to implement depending on what you do.

You might be wondering "why didn't the creators of ethereum give us the ability to create a "callback function" that would run on regular intervals?". Full disclosure, I'm not as familiar with the EVM "Ethereum Virtual Machine" internals and maybe things have changed but I think it's because this callback function would have to sit in the memory of every single ethereum node. There's currently 6339 ethereum nodes at the time of writing, and having that many nodes hold onto your function forever is prohibitively expensive and impractical. I still have lots to learn though, so someone is free to correct me if I have the wrong understanding. ☮!