Skip to content

Commit

Permalink
Create BlockchainBasicsContract.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 20, 2024
1 parent d41f27c commit c14fa18
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions contracts/BlockchainBasicsContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pragma solidity ^0.8.0;

import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";

contract BlockchainBasicsContract {
// Mapping of user addresses to their progress
mapping(address => uint) public progress;

// Event emitted when a user completes a lesson
event LessonCompleted(address indexed user, uint lessonId);

// Event emitted when a user earns a badge
event BadgeEarned(address indexed user, uint badgeId);

// Struct to represent a lesson
struct Lesson {
uint id;
string title;
string description;
uint reward;
}

// Struct to represent a badge
struct Badge {
uint id;
string title;
string description;
uint requirement;
}

// Array of lessons
Lesson[] public lessons;

// Array of badges
Badge[] public badges;

// Function to complete a lesson
function completeLesson(uint _lessonId) public {
// Check if the user has already completed the lesson
require(progress[msg.sender] < _lessonId, "Lesson already completed");

// Update the user's progress
progress[msg.sender] = _lessonId;

// Emit the LessonCompleted event
emit LessonCompleted(msg.sender, _lessonId);

// Check if the user has earned a badge
for (uint i = 0; i < badges.length; i++) {
if (badges[i].requirement <= _lessonId) {
// Emit the BadgeEarned event
emit BadgeEarned(msg.sender, badges[i].id);
}
}
}

// Function to get a user's progress
function getProgress(address _user) public view returns (uint) {
return progress[_user];
}
}

0 comments on commit c14fa18

Please sign in to comment.