In Part 1 of this 2-article series we had a theoretical approach towards monetizing your Ethereum DApps. In this part we will look at some code examples that show how you can actually implement them in Solidity.

Withdrawing Funds

To start with, there needs to be a function that will allow the withdrawal of the funds to the owner’s address. This is as simple as:

This function will transfer the balance of the calling contract to the address at owner (using the very popular onlyOwner modifier pattern). If you are unfamiliar with how the keywords above work, you might want to stop reading here and resume after completing our lessons at

Disclaimer: All of the following examples are simplified to illustrate how you can implement only the discussed functionalities. We make assumptions about the business logic, and we do not take any rigorous security measures that we would take when creating a suite of smart contracts. Always do a full security audit of your code before pushing to production!

1. Create a Crowdsale / Launch a Token

This has been described in the Official Ethereum Webpage. In order to create a secure crowdsale, it is recommended to use the audited contracts created by Open Zeppelin.

You can follow this guide, or this video for that purpose.

2. Premium Functionality / Skip the Effort

View the whole code at:

In this case, we can see that a user can bypass the winCount requirement for leveling up, by paying 1 ether. The owner would then call the previously discussed withdraw function so that they get their funds.

Note that the price of Ether may go up (or down) drastically in the future, which would change the cost of your premium feature. So in a lot of cases it makes sense to add an onlyOwner function that allows you to change the cost in the future, otherwise your app may become prohibitively expensive. This goes for all the following examples as well.

3. Take a percentage of marketplace transaction fees

In this (much simplified) example, when someone wants to buy a zombie, 10% of the price gets sent to your wallet, while the rest gets transferred to the zombie’s owner.

View the whole contract at:

In order to save some gas costs, you can skip the first line of the function, which will instead leave the ether at the contract’s balance. By using the withdraw function we described earlier, you can at a later point in time withdraw all the ether that the contract has.

4. Subscription / Membership

Here we will look at examples of implementing subscription / membership business models for:

  1. Lifetime
  2. Time-based
  3. Usage-based

We will create a contract where certain functions will only be callable by individuals which have been marked as eligible.

Lifetime Membership

This is a simple case of creating a boolean mapping, a modifier that checks if the boolean is true, and a function that allows a user to become a member for some price.

View the whole contract at:

Alternatively, instead of using a boolean for member/non-member, we could use a uint8 and have different membership tiers with access to more and more features: tier 0 for free users, tier 1 for silver membership, tier 2 for gold membership, etc. Then onlySilver() could check if the membership tier is >= 1.

Simple enough, let’s move on.

Time-Based Membership / Subscription

Here our business model will assume that the subscription costs 0.005 ether per day.

View the whole contract at:

In this case when a user calls the renewSubscription function, the subscriptionExpiration gets initialized to now if necessary, and then increased by a number of days depending on how much the user paid. The onlyMember modifier can be used to check if the current time has passed the expiration date.

Usage-Based Membership / Pay-per-use

Here the business model involves a user buying function calls upfront, similarly to how you can buy API calls at a set price.

In this example, a user can buy 1000 calls per ether. Every time a user makes a call to a function that has the onlyIfEnoughCalls modifier, after checking that they are eligible for the call, the availableCalls variable is decremented.

View the whole contract at:

In all of the above scenarios, you could simply add the corresponding only{property} modifier to any function, and then it would only be callable by the users who are authorized to access it.


In this 2-part article series we discussed and implemented some business models you can apply to your DApp when your goal is to monetize it.

I want to emphasize that all the code given in this post is a very basic implementation of each model and should be adapted to your exact needs.

Next Steps:

Interested in DApp development? Check out our totally free course for how to get started ⬆

Loom Network is the blockchain platform of choice for serious dapp developers — the Universal Layer 2 that provides developers the tools they need to build functional user-facing dapps today.

New to Loom? Start here.

Want to stake your LOOM tokens and help secure Loom Network? Find out how.

And if you enjoyed this article and want to stay in the loop, go ahead and sign up for our private mailing list.

Loom Network

🛸 The production-ready, multichain interop platform for serious dapp developers —

Thanks to James Martin Duffy

Georgios Konstantopoulos

Written by

Independent consultant & engineer focused on blockchain scalability, infosec and mechanism design. That Layer 2 guy. Aspiring Rustacean.

Loom Network

🛸 The production-ready, multichain interop platform for serious dapp developers —

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade