Mapping and Address Management in Solidity

Introduction

Solidity, a high-level language for writing smart contracts on platforms like Celo, provides various data types and features to handle complex tasks. This challenge emphasizes utilizing mappings and addresses in Solidity for effective data management.

Problem Statement

Create a contract that manages user profiles on a mock social network platform. The contract should have the following features:

  1. It should allow a user to create a profile using their address.
  2. The profile should include details such as username, first name, and last name.
  3. It should prevent an address from creating more than one profile.
  4. The contract should include a function to update the profile details.
  5. The contract should allow retrieving the profile details of a user using their address.
  6. Implement a function to check if a user profile exists or not.

Hints

  • Use Solidity’s mapping keyword to map an address to a profile.
  • Create a struct to store user profile details.
  • msg.sender global variable can be used to associate a profile with an address.
  • require() function can be utilized to enforce rules such as one-profile-per-address.

Evaluation Criteria

  • Correctness: The contract should compile without errors and meet all requirements.
  • Readability: The contract should be well-documented, with comments explaining the code.
  • Testability: You should also provide examples of how to test each function of the contract.

Remember, this challenge mainly focuses on data management using mappings and addresses and doesn’t cover other important aspects like security and gas optimization, which are crucial for real-world applications on the Celo platform.

For a comprehensive understanding of Celo smart contracts and Solidity, please refer to the Celo and Solidity tutorials.

Submission

Please reply with a link to your PR on https://github.com/celo-academy/Mapping-and-Address-Management-in-Solidity-Coding-Challenge, including your user profile management contract. Also, include any notes or comments you think are necessary to understand your design and choices. Lastly, provide a brief explanation about how each function of the contract should be tested.

2 Likes