18
21 Comments

How I made a Web3 app to reward my community with tokens

When I started my web3 journey I got a freelance contract: Add web3 features to an existing app and reward the users with our token.

The point of rewarding the community was:

  • To motivate the community to do something to earn a token.
  • The brand wanted to have its own token to improve branding.
  • Rewarding the user with tokens is becoming more and more common these days.

Our users should get 5 tokens when completing their profile (bio, curriculum, social media links, etc.).

But we could imagine rewarding users for many other kinds of actions, such as: commenting on a post or sharing a post on social media.

Create a token ⚒️

The first major task was to create a token.

After some research and discussions with other DEV, I decided to use an ERC-20 token.

I made one million token supplies and decided to lock half of it using a time lock contract.

Locking tokens is for purpose to give trust to your tokens to your users.

Get the wallet public ID of the user 🆔

Then, I had to connect my front-end to Metamask API (or to wallet connect)

The goal is to get the wallet public ID of my users.

With this wallet public ID I will be able to transfer to theses users my reward’s tokens.

I also needed to add our token to their Metamask wallet. Which was something I could handle with the Metamask API.

I then simply saved the wallet public ID on the user table. I will use this public ID later.

Reward the users when they complete their profile 👏

When a user completes his profile on the app we need to send him 5 tokens.

Firstly I made a « reward » table on the back-end. I want to know whether that specific type of reward was already given to this user.

Then on my back-end, I needed to make an endpoint that would trigger a function to make a token transaction.

To make a transaction I used etherJs on my NodeJs app. When the conditions are met, I make a new transaction from my wallet ID to the user walletID.

I also pay the gas fee using my wallet automatically. My server can access my wallet using my wallets private key.

When a transaction is successful, the user will get a notification and the token will appear in his wallet.

Deploy our token to the Polygon network 🕸

Using Ethereum network is expensive when it comes to pay gas fee. That’s one of the reasons we decided to go for Polygon Matic.

Polygon is also a part of the blockchain network. However, the cost to operate is well cheaper than on Ethereum.

On localhost I was using a Testnet network. A fake network, that I set up with HardhatJs.

I now needed to push my ERC-20 token to Polygon network.

I used again HardhatJs in order to deal with this.

Security concerns 🔒

When it comes to Web3 and Blockchain, I had to make sure that my setup was safe 😀

By safe I mean:

  • I don’t want bots to be able to make thousands of transactions.
  • I don’t want people to use my wallet ;)

This is what I did for this app:

  • I stored the wallet private key on the environment global variables of my server.
  • That wallet contains only a few Ethers. Enough to pay a few months of gas fee
  • That wallet contains only 1% of the tokens we created.
  • A user cannot get multiple reward tokens for the same type of reward. For example, the type of reward was « set-up-profile-reward ».
  • Only logged users will get a reward.
  • We verify that the user is the right one by signing the bearer token. We stored the signature of that bearer token on the server.

This is how that process looks:

Screen Shot 2022-02-04 at 2.23.45 PM.png

What’s Next?

I’m planning in the future, to release Saas App using Web3 and to accept more freelance contract using that technology.

👉 You can follow me there on Twitter, as I continue to document my journey.

  1. 1

    just wow imo, ur own work is a clear guide to merge between and go from web2 to the web3, great experience add to mine

  2. 1

    Hey Romain,
    Thanks for sharing interesting. From your experience how easy is it to go from a Web 2.0 project to a Web 3 project ?

    I have an actual mvp around communities built on 2.0 and I was wondering to transform it in 3.0 what would be the actual work needed ?
    Is it just an add-on you add (by giving tokens) or do you need to rebuild and refactor the whole code ?

    1. 1

      Hey
      Really depends what are your needs and what is your current codebase using ;)
      For the project I mentioned in this article, there was already a huge codebase with a front-end (VueJs) and a back-end using NodeJs

      I didn't have to refactor all the code,

      I just had to add some new end-points to the back-end. And some additional logic to handle the smart contracts
      I also needed to add the wallet feature on the front-end

      You can contact me on tweeter @devvnomad, I might be able to give you a better idea of what needs to be done once I see your current project, 😀

      1. 1

        Sure romain ! Thanks for the tip - Will ping you when I tackle this topic :)

  3. 1

    Very helpful article for how to implement Web3 features. Thanks for that!
    How this is actually from a legal persepctive? I'm currently also investigating a little in the virtual currency space and theoretically users can trade their coins, right? Is this simply possible without registering as - don't know - a money-business?
    (Sorry for the noob question, I'm very new to the space...)

    1. 1

      Without registering?
      The thing is, you need their wallet public ID in order to send them tokens.
      There are 2 solutions to achieve that today:

      • The users login/register with an email/SSO and then you request from them, their walletID using Metamask API(or any other wallet provider)
      • Or, you set up the authentication using web3, some services like moralis.io are pretty good and simplify that process. Once authenticated, you will also get the wallet public ID of the user

      Once you have that wallet public ID, you will be able to:

      • Send tokens to your users.
      • Let users send tokens to other users.

      In most country, except China, I don't think there is any issue trading coins today,

  4. 1

    I think this is a really good idea. A few weeks ago I met a start up founder who rewards users with their tokens for certain actions. This is really cool for users who want to get crypto, but don't want to go through all the pain of signing up to an exchange.

    1. 1

      yes that process getting more and more popular

  5. 1

    this is awesome! I am building an app that rewards tokens for usage. Looking for an advisor. Care to connect? https://twitter.com/thenishantmodi

    1. 1

      thanks, Sure, adding you

  6. 1

    Great article. I will like to connect on Twitter because am trying to explore web3 during a particular weekend and build something on that weekend. You'll be of great help

    1. 1

      hey you can find me on Twitter at @devvnomad

  7. 1

    Nice article thanks for make it

  8. 1

    Awesome post Romain! Thank you! We’re looking to integrate web3 at Chessroulette, and you post helps a lot!

    1. 1

      sounds interesting, what type of Web3 feature do you plan to integrate into chessroulette?

      1. 1

        Looking at gamification through tokens, NFTs as passes to events/community, a web3 version of chess to name a few :).

        I'm even thinking of an NFT kickstarter campaign to raise money. Would like to talk to someone with experience to come up with a roadmap.

        Does this sound like smtg of interest to you?

        1. 1

          surely could, let's connect on Twitter @devvnomad

  9. 1

    This is super helpful, thanks!

    1. 1

      good to know! thanks;

Trending on Indie Hackers
Reaching $100k MRR Organically in 12 months 29 comments What you can learn from Marc Lou 20 comments Worst Hire - my lessons 11 comments How to Secure #1 on Product Hunt: DO’s and DON'Ts / Experience from PitchBob – AI Pitch Deck Generator & Founders Co-Pilot 10 comments Competing with a substitute? 📌 Here are 4 ad examples you can use [from TOP to BOTTOM of funnel] 9 comments 87.7% of entrepreneurs struggle with at least one mental health issue 8 comments