This is a smart contract I wrote using Solidity that lets people register and update their profile on the blockchain. It was one of the first contracts I built to understand how user data works on Ethereum.
The idea is simple:
Everyone has a wallet address. What if we could let each address store their name, age, and email - all saved on-chain?
So I built that.
Here is the GitHub link if you want to check out the code.
I wrote just one file: UserProfile.sol
.
What This Contract Does
This smart contract lets a user:
- Register their name, age, and email
- Update that information later
- View their own profile (no one else can access it)
Everything is connected to their Ethereum wallet address, so you don’t need to log in - your wallet is your ID.
Concepts I Used
If you're new to Solidity or smart contracts, these are the main building blocks I used:
Concept | What It Does |
---|---|
struct |
Groups related data - like name, age, and email - into a single object |
mapping |
Stores info for each user using their wallet address as the key |
require() |
Adds checks so people don’t register twice or update before registering |
block.timestamp |
Saves the time a user registered, using the blockchain’s clock |
Each time someone registers, their info is stored on the blockchain - and only they can update or view it.
How It Works
Here’s what the contract does in plain English:
1. register(name, age, email)
This function saves your profile to the blockchain - but only if you haven’t registered before. If you try again, it gives an error.
2. updateProfile(name, age, email)
If you already registered, this lets you change your info anytime.
3. getProfile()
This function shows your current profile - your name, age, email, and the time you first registered. Only you can see it (based on your wallet).
How to Try It Yourself (Beginner-Friendly)
You don’t need a real wallet or ETH to test this. Remix IDE runs everything in your browser using fake ETH.
Steps to Test the User Profile Contract
Go to Remix
→ https://remix.ethereum.orgCreate a new file
→ Click “+” → Name itUserProfile.sol
Paste in the contract code
→ You can find it here on GitHubCompile it
→ Go to the Solidity Compiler tab
→ Make sure version is0.8.0
or higher
→ Click CompileDeploy it
→ Go to the Deploy & Run Transactions tab
→ Select Remix VM (Prague) as environment
→ Leave Value as0
→ Click DeployRegister yourself
→ Fill in name, age, and email
→ Clickregister()
✅ You’ll see a green checkmarkCheck your profile
→ ClickgetProfile()
✅ Your info will appear: name, age, email, and timestampTry updating it
→ Enter new name, age, or email
→ ClickupdateProfile()
→ Then clickgetProfile()
again to see the updated info
What I Learned
Lesson | How I Used It |
---|---|
Structs in Solidity | Grouped user info like name, age, email |
Mappings | Stored each user's profile by their address |
Access control with msg.sender
|
Made sure only the owner of a profile can update or view it |
Blockchain timestamp | Recorded when each user registered |
Remix testing | Quickly deployed and tested without real ETH |
Common Mistakes to Avoid
Mistake | Why It’s a Problem | How I Solved It |
---|---|---|
Registering twice | Contract would overwrite data | Used require() to block double registration |
Updating before registering | User wouldn’t exist in mapping yet | Added require() to check registration first |
Returning too much data | Could make view functions heavy |
Kept getProfile() simple and clear |
Up Next
In the next post, I’ll show you how I built a Vault app where users can deposit and withdraw ETH securely - and how I used Solidity libraries and events for better logic and tracking.
We’ll also test that app step-by-step in Remix.
I’d really appreciate your questions or feedback. Did something confuse you? Let me know. Your insights help shape the next articles.
Also, if there’s a non-Web3 topic you want me to cover (open source, side projects, etc), drop a comment below. If I know it, I’ll write about it. If not, I’ll point you to a good place to begin.
🤝 Stay in Touch
- Check out the GitHub repo
- Follow me on GitHub for projects and experiments
- Connect with me on LinkedIn - I’d love to hear from you
- Drop a comment if you tried this or have questions - I’d love to help!
📚 Also, if you’re new to Web3 in general...
I’m writing another beginner-friendly series called “Foundations of Web3: A Beginner’s Journey”. It covers wallets, testnets, transactions, and more - in simple language.
You can check it out here:
👉 Foundations of Web3: A Beginner’s Journey
Thanks for reading!
Top comments (0)