DEV Community

Cover image for πŸš€ Day 2 of 30 Days of Solidity Challenge – Building Enhanced User Profiles
Saurav Kumar
Saurav Kumar

Posted on

πŸš€ Day 2 of 30 Days of Solidity Challenge – Building Enhanced User Profiles

Hello developers πŸ‘‹

This is Day 2 of my 30 Days of Solidity Challenge where I share my learning journey while building small but useful smart contracts.


πŸ“Œ Task for Today

Yesterday, we built a simple contract that stored just a user’s name and bio.
Today, I enhanced that contract to make it feel more like a real user profile system.

We added extra fields like:

  • Username
  • Bio
  • Age
  • Location
  • Profile Picture (can be an IPFS hash or URL)
  • JoinedOn (timestamp when profile was created/updated)

πŸ“ Smart Contract – Enhanced Profile

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract EnhancedProfile {
    struct Profile {
        string username;
        string bio;
        uint256 age;
        string location;
        string profilePic;  // could store IPFS hash or URL
        uint256 joinedOn;
    }

    mapping(address => Profile) private profiles;

    event ProfileUpdated(
        address indexed user,
        string username,
        string bio,
        uint256 age,
        string location,
        string profilePic
    );

    function setProfile(
        string memory _username,
        string memory _bio,
        uint256 _age,
        string memory _location,
        string memory _profilePic
    ) public {
        profiles[msg.sender] = Profile({
            username: _username,
            bio: _bio,
            age: _age,
            location: _location,
            profilePic: _profilePic,
            joinedOn: block.timestamp
        });

        emit ProfileUpdated(msg.sender, _username, _bio, _age, _location, _profilePic);
    }

    function getProfile(address _user)
        public
        view
        returns (
            string memory username,
            string memory bio,
            uint256 age,
            string memory location,
            string memory profilePic,
            uint256 joinedOn
        )
    {
        Profile memory profile = profiles[_user];
        return (
            profile.username,
            profile.bio,
            profile.age,
            profile.location,
            profile.profilePic,
            profile.joinedOn
        );
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ž How It Works

  1. Struct Profile β†’ Stores all user details.
  2. Mapping (address => Profile) β†’ Each wallet address is linked to its profile.
  3. setProfile() β†’ Users can create or update their profile.
  4. getProfile() β†’ Anyone can fetch a profile by providing the wallet address.
  5. Event ProfileUpdated β†’ Logs every update, useful for dApp frontends.

⚑ Example Usage

  • A user saves their profile:
setProfile("Alice", "I build dApps", 25, "Bangalore, India", "ipfs://QmHashOfPic");
Enter fullscreen mode Exit fullscreen mode
  • Anyone can retrieve Alice’s profile:
getProfile(aliceAddress);
Enter fullscreen mode Exit fullscreen mode

➑️ Returns all details including the timestamp.


🎯 Learning Outcome

With this task, I learned how to:
βœ… Store multiple user details on-chain.
βœ… Use structs + mappings effectively.
βœ… Add events for tracking profile changes.
βœ… Design a basic identity system for future dApps.


This is a small but important step towards understanding data storage & retrieval in Solidity. Tomorrow, I’ll move to the next challenge and keep building!


πŸ‘‰ You can also check out Day 1 blog here: Day 1 of Solidity Challenge – Click Counter

Stay tuned for Day 3 πŸš€


✨ Thanks for reading! If you’re also learning Solidity, let’s connect and build together.

Top comments (0)