Last active
April 5, 2025 05:05
-
-
Save KBPsystem777/59a56652d823476640671e4a97a69ffd to your computer and use it in GitHub Desktop.
Sonic CodeCamp Activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.19; | |
/// @title Interface for ClassmateConnect | |
interface IClassmateConnect { | |
function registerProfile( | |
address _studentAddress, | |
string memory _nickname, | |
string memory _bio | |
) external; | |
function getProfile(address _studentAddress) | |
external | |
view | |
returns ( | |
string memory, | |
string memory, | |
address | |
); | |
function addComment( | |
address _studentAddress, | |
address _commenter, | |
string memory _message | |
) external; | |
function getComments(address _studentAddress) | |
external | |
view | |
returns (address[] memory, string[] memory); | |
} | |
/// @title StudentContract - Individual student interaction contract | |
contract StudentContract { | |
address public owner; | |
IClassmateConnect public parentContract; | |
// ⚠️ #1 @todo Add an event to log a comment from student | |
constructor( | |
string memory _nickname, | |
string memory _bio | |
) { | |
owner = msg.sender; | |
parentContract = IClassmateConnect(0x8e4C7Ef963884b8a804BFdF2324b62c1daBC9660); | |
// Register student profile on the parent contract | |
parentContract.registerProfile(owner, _nickname, _bio); | |
} | |
/// @notice View a classmate's profile | |
function viewClassmateProfile(address _classmate) | |
external | |
view | |
returns ( | |
string memory, | |
string memory, | |
address | |
) | |
{ | |
return parentContract.getProfile(_classmate); | |
} | |
// ⚠️ #2 @todo Add a function named commentOnClassmate to allow commenting on a student profile | |
// ⚠️ #3 @todo Inside commentOnClassmate function, Emit the CommentSubmitted event after submitting a comment | |
/// @notice View comments on a classmate's profile | |
function viewClassmateComments(address _classmate) | |
external | |
view | |
returns (address[] memory, string[] memory) | |
{ | |
return parentContract.getComments(_classmate); | |
} | |
} |
Answer #1
event CommentSubmitted(address indexed student, string message);
Answer #2 & #3
function commentOnClassmate(address _classmate, string memory _message)
external
{
require(bytes(_message).length > 0, "Message cannot be empty");
parentContract.addComment(_classmate, msg.sender, _message);
// Emitting the CommentSubmitted event
emit CommentSubmitted(_classmate, _message);
}
Sonic RPC
sonic: {
url: "https://rpc.blaze.soniclabs.com",
accounts: [deployerPrivateKey],
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ClassmateConnect Address Book: https://bit.ly/classmate-address
ClassmateConnect Parent contract address:
0xBa0F76C6B6Ccb65aba626a627dCf161975e2EE8C