Use tokenization to convert membership into the ownership of coins which will be spent to gain access, use premium amenities, purchase merchandise, and purchase other services of value.
From a user's perspective, tokenization can also provide consumption data so that users can determine their own behavior and spending habits.
For the purpose of this project, we will focus on using blockchain to determine the fluctuation of the cost per visit, based on how many users have spent tokens to access the gym at any point in time.
This project leverages the following tools:
- Solidity - programming language for implementing smart contracts
- Remix IDE - open source tool that helps you write Solidity contracts straight from the browser; has modules for testing, debugging, and deploying of smart contracts
- Ganache - A program that allows you to quickly set up a local blockchain, which you can use to test and develop smart contracts
- MetaMask - allows users to store and manage account keys, broadcast transactions, send and receive Ethereum-based cryptocurrencies and tokens, and securely connect to decentralized applications through a compatible web browser or the mobile app's built-in browser
- Streamlit - Turns data scripts into shareable web apps using Python
- Web3.py - A Python library for connecting to and performing operations on Ethereum-based blockchains
The Solidity version used for this project was the following:
pragma solidity ^0.5.5
Ganache network: w3 = Web3(Web3.HTTPProvider('HTTP://127.0.0.1:7545'))
OpenZeppelin libraries that were imported in the Remix solidity contract:
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Detailed.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20Mintable.sol";
If you do not already have the required technologies installed, install them now through your terminal. For example:
pip install streamlit
pip install web3==5.17
If you do not already have MetaMask and Ganache installed, install them now:
- Download and install the MetaMask browser extension. Follow the instructions here to install it.
- Download and install the lastest version of Ganache. Follow the instructions here to install it. To create a workspace, click on "Quickstart Ethereum".
- Open Remix IDE
- Open the smart contract file (
FlexCoin.sol) in Remix IDE. (You may need to create a new file and copy and paste the Solidity code to the file) - While in the
FlexCoin.solfile, select the "Solidity Compiler" tab and press the button that says, "Compile FlexCoin.sol" - Open Ganache and Metamask
- Copy the Ganache RPC Server: HTTP://127.0.0.1:7545
- Create and save a new network in MetaMask (for example, you can name it "devNetwork")
- Open MetaMask and choose Import Account
- Go to Ganache and copy a private key for the account
- Go to MetaMask to paste the private key and import/create the account
- There should be 100 ETH in the account, and the last 4 digits of the account in MetaMask should correspond to the last 4 digits of the account address in Ganache
- Repeat steps 7-10 to create one more account so that you now have 2 accounts in MetaMask connected with two different addresses in Ganache
- Select the "Deploy and Run Transactions" tab and choose the environment of Injected Web3. This should open MetaMask
- Verify the connection to MetaMask and select the accounts that you want to be linked to the Remix contract and connect them
- Deploy the FlexCoin contract (remember to fill in the required boxes of 'name', 'symbol', and 'initial_supply' before deploying)
- Copy the smart contract address of the deployed contract and paste it into the SAMPLE.env file next to 'SMART_CONTRACT_ADDRESS'
- Copy the first account address from Ganache (i.e., owner account) and paste it into the SAMPLE.env file next to 'OWNER_ADD'
- Import FLEX token to the MetaMask accounts under the "Assets" tab
- Use the functions in Remix IDE to mint coins to the owner and add minters
- Run the streamlit application by typing the following into your terminal:
streamlit run gym_app.py - Interact with the Streamlit drop down menus and buttons (See examples below)
Here is a quick preview of how the application works:
On the Streamlit app, you will first choose an account (10 accounts are loaded in from Ganache; the accounts need to be connected to MetaMask in order to work):

The app tells the user how many tokens they currently have and describes the monthly membership costs:

The user can use the "Purchase membership tokens" button to purchase the 50 membership tokens:

As a result, the token amount for the account increased by 50 tokens:

If a user needs more tokens, additional tokens can be purchased using the slider:

The user can click the "Get Current Price" button to see how many people are at the gym and how much it costs to enter based on the number of people at the gym:

The user clicks the "check in" button to check in for that price (5 tokens in this example):

There is also a Gym Store where users can purchase gym-related items:

In this example, the member uses the slider to purchase 3 water bottles at a cost of 9 tokens. The member clicks the "Purchase Item(s)" button, and the transaction receipt appears on the center of the app:

Kevin BaRoss
Rachel Bates
Michael Canavan
Catherine Croft
Vic Gellon
MIT

