Empowering Positive Behavior with Blockchain-based Betting: a Proof of Concept

Using Ethereum, Web3 JS & Google Fit API

I firmly believe that economic incentives are the best ways to encourage a specific behavior (I will soon write an article about it).

And I also think that blockchain is the optimal technical architecture to create systems based on economic incentives thanks to enforceability of contracts, low transactions costs and transparence. (I will cover this in the article as well!)

Thus, I developed a POC (currently named "Friend Betting") that allow people who know each others to make bets using cryptocurrencies.

If you want to dive deeper or collaborate, the code is available on my Github !

Understand the Idea with some User-storys

  • Alice wants to foster a positive work emulation among her friends for the next Maths exam. They organize a bet where the highest grade wins the entire pool amount.
  • Satoshi, the CEO of Nioctib, seeks to promote health within his company by setting $1M in a pool. After 100 days, the pool is distributed proportionally based on the number of steps taken by the employees.
  • Bob wants to encourage his children to reduce their phone usage. He creates a pool with $100. Each day, the child who spends the least amount of time on the phone wins $1.

A First Implementation: An Admin Manually Manages a Bet Between Several Players

What

  • An admin creates a pool with several whitelisted addresses.
  • The whitelisted addresses contribute to the pool (currently in ETH cryptocurrency, though ERC20 tokens could also be used).
  • The admin assigns a score to each address, and the one with the highest score can withdraw the money from the pool.

How

  • Develop a basic code in Solidity on Remix IDE and deploy it on a devnet.
  • ... Code available Here
  • Include the contract functions in a basic application using an Infura key for Web3.js
  • Deploy a UI on a local server for interaction with a Metamask wallet on a testnet (Sepolia).
  • ...

Why

  • To address Use Case #1 (Alice and the maths exam).
  • To create a local dapp encompassing the entire lifecycle: Blockchain > App > User Interface.

A Second Implementation: A Walker Can Withdraw if He/She Reaches X Steps

What

  • An admin creates a pool, sets a unique walker address, and adds some value to the pool.
  • An external hardware (usually a smartphone) monitors the walker's step count.
  • The step count is compared to a 1,000 steps goal.
  • If the walker reaches 1,000 steps in a day, he/she is allowed to withdraw the money from the pool.

How

... The architecture here is more complex, so I created a diagram for better understanding:
  1. Connect a local server to the Google Fit API and fetch the number of steps.
  2. ...
  3. Write a basic code in Solidity on Remix IDE and deploy it on a testnet (Sepolia).
  4. ... Code available Here
  5. Using Web3.js, trigger the Ethereum address to call the smart contract when the number of steps exceeds 1,000.
  6. ... ...

Why

  • To address a combination of Use Cases #2 and #3.
  • To enable interaction between real-world data and the Blockchain through APIs and event-driven Ethereum addresses.

Review & Conclusion

Results

The two implementations are basic, non-optimized, and full of potential security and decentralization issues.

However, it's amazing to see how quickly the Blockchain layer can leverage use cases involving value transfers, thanks to the enforceability of contracts, low transaction costs, and transparency.

Blockchain is inevitable.

What I Learned

  • How to request data from a smartphone using Google API services.
  • The process of creating a dapp on the full lifecycle: Blockchain > App > User Interface. (This was my first experience managing the Blockchain component, I only have a background in Dapp backend and UI development).
  • How to create and use an event-driven Ethereum address.

If you're interested in diving deeper or collaborating, the code is available on my Github!