Skip to content

Instantly share code, notes, and snippets.

@KBPsystem777
Last active April 5, 2025 05:05
Show Gist options
  • Save KBPsystem777/59a56652d823476640671e4a97a69ffd to your computer and use it in GitHub Desktop.
Save KBPsystem777/59a56652d823476640671e4a97a69ffd to your computer and use it in GitHub Desktop.
Sonic CodeCamp Activity
// 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);
}
}
@KBPsystem777
Copy link
Author

KBPsystem777 commented Feb 10, 2025

@KBPsystem777
Copy link
Author

KBPsystem777 commented Feb 11, 2025

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);
    }

@KBPsystem777
Copy link
Author

KBPsystem777 commented Apr 5, 2025

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