The Blockchain-Based Authentication and Incentive System is a cutting-edge solution designed to elevate user authentication, security, and engagement for companies. By harnessing the power of blockchain technology, this system bids farewell to conventional authentication methods like email or usernames. Companies registering on the blockchain will deposit an initial asset, acting as an incentive for their active users.
- Companies register on the blockchain and deposit an initial asset.
- Blockchain ensures transparency, immutability, and trust in the registration process.
- User registration relies on a secure combination of wallet address and password, enhancing privacy and security.
- No need for traditional email or username-based authentication.
- Companies conduct user sessions, authenticate users, and track regular sessions.
- User login data is updated daily to monitor user activity.
- Smart contracts come into play, rewarding active users with incentives.
- Users with consecutive active days receive rewards based on predefined criteria.
- Companies are responsible for regular updates of users' login data.
- Failure to update login data is flagged, and companies may be deemed untrustworthy.
To get started with the Blockchain-Based Authentication and Incentive System, follow the steps below:
- Node.js - Ensure Node.js is installed.
- Ganache - Required if deploying locally.
- MongoDB - MongoDB for database storage.
- MetaMask - A crypto wallet and gateway to blockchain apps.
- Open a new terminal.
- Navigate to the
blockchain
directory.
cd blockchain
- Create 3 MetaMask accounts (Owner of the contract, Company account, User).
- Alternatively, import accounts from Ganache if using it as a local blockchain.
- Ensure that the owner of the contract and company account has some ETH balance to cover gas costs.
- Open a terminal and go to
contracts
folder into theblockchain
directory.
cd blockchain/contracts
- Install dependencies:
npm install
- Configure the
.env
file andhardhat.config.ts
in theblockchain
directory:
- For Sepolia Testnet, use:
API_URL=https://eth-sepolia.g.alchemy.com/v2/your-api-key
- For Ganache, use:
API_URL=http://127.0.0.1:7545
- The private key should belong to the owner of the smart contract.
API_URL=http://127.0.0.1:7545
# Make sure the private key has a prefix of 0x.... (If it doesn't exist, add it)
PRIVATE_KEY=your_private_key
To ensure all contracts within the blockchain/contracts
directory use the Solidity version 0.8.24
and to configure your Hardhat environment to use the same version.
Ensure that each Solidity contract file in the blockchain/contracts
directory has the following header:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;
// Rest of the code
In your hardhat.config.ts
file, set the Solidity version to 0.8.24
.
const config: HardhatUserConfig = {
solidity: "0.8.24", //Similar to Solidity version
//Rest of the code
};
npx hardhat compile
After compiling the smart contracts, copy the AuthenticationServiceProvider.json
file from the blockchain/contracts/AuthServiceProvide.sol/AuthenticationServiceProvider.json
directory and paste it into the backend/contracts
directory.
npx hardhat run deployments/deploy.js --network networkName
After executing the previous command, you should see something like this:
Contract Deployed to Address: 0xc5cCbE0F358643b3DdCC13d2667......50
0xc5cCbE0F358643b3DdCC13d2667......50
is your smart contract address.
- Open a new terminal.
- Navigate to the
backend
directory.
cd backend
- Install dependencies:
npm install
- Configure the
.env
file in thebackend
directory:
PORT=4000
DB_URI="mongodb://127.0.0.1:27017/your_db_name"
company_privateKey=your_company_privateKey
contractAddress=your_contract_address
userWalletAddress=your_user_wallet_address_for_testing_consecutive_logins_by_custom_script_if_using_ganache
#For network based RPC URL eg. sepolia - RPC_URL="https://eth-sepolia.g.alchemy.com/v2/your-api-key"
#For Ganache
RPC_URL="http://127.0.0.1:7545"
- Start the backend server
npm run dev
Follow these steps to set up the frontend of the project.
Open a new terminal to execute the commands.
Use the following command to navigate to the frontend
directory.
cd frontend
Install project dependencies with the following command:
npm install
Once the dependencies are installed, start the frontend server using the following command:
npm run start
This will launch the development server, and you can access the frontend by visiting http://localhost:3000/ in your browser.
Navigate to http://localhost:3000/company to register your company name and deposit ETH. Connect your company's Metamask wallet for the transaction.
Connect the Metamask wallet of the user's account. Register the user using the wallet address and password, then log in to interact with the web app.
After seven consecutive days of login, the user will receive automatic rewards. To simulate this with Ganache:
- Open a new terminal.
- Navigate to the
backend
directory.
cd backend
- Update the
userWalletAddress
in the.env
file with the user's wallet address for whom you want to simulate seven days of consecutive login (Only Ganache). - Run the following command:
npm run custom
Enjoy exploring the application!
π We welcome contributions, bug reports, and feature requests. Feel free to fork the repository, open issues, and submit pull requests to contribute to the continuous improvement of the Blockchain-Based Authentication and Incentive System.
This project is licensed under the MIT License.
This project is under active development, and features may change. Use at your own risk.
We express gratitude to the open-source community and various contributors for their valuable input and feedback in shaping this project.
Join us in revolutionizing authentication and engagement in the digital era! π