My First Smart Contract with Solidity: The Mood Logger Project


Have you ever wanted to record how you feel on the blockchain? No, seriously, imagine telling Ethereum that you're feeling awesome today. That’s exactly what you’ll learn to do in this article. If you're new to Solidity and Remix IDE, this is the perfect project as a beginner to get your hands dirty. It's called the Mood Logger, and it's simple, personal, and kind of fun. You’ll learn how to write and deploy a smart contract that allows anyone to store and retrieve their current mood. Let’s walk through it together.
What is the Mood Logger?
The Mood Logger is a basic Ethereum smart contract written in Solidity. It allows each wallet address to:
Set their current mood (like “productive”, “tired”, or “excited”)
Get their current mood (based on their wallet)
This might sound simple, but under the hood, it teaches you some key blockchain programming concepts like:
Mappings
msg.sender
Function visibility (public, view)
Remix IDE and MetaMask integration
Step-by-Step: Writing the Smart Contract
Let’s start by writing the contract in Remix.
Step 1: Open Remix IDE
- Go to Remix IDE in your browser.
Step 2: Create a New File
- On the left sidebar:
Click the File icon
Click “Create New File”
Name it: MoodLogger.sol
Step 3: write the Smart Contract Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
contract MoodLogger {
// Mapping to store moods per user address
mapping(address => string) private moods;
// Set your current mood
function setMood(string memory mood) public {
moods[msg.sender] = mood;
}
// Get your current mood
function getMood() public view returns (string memory) {
return moods[msg.sender];
}
}
What the Code Contains
A brief lecture:
SPDX License Identifier
// SPDX-License-Identifier: MIT
Purpose: Declares the license type of the code. Here, MIT is a permissive open-source license.
Importance: Required by Solidity compilers from version 0.6.8 and up. It helps others understand how they can legally use your code.
Pragma Directive
pragma solidity ^0.8.5;
Purpose: Specifies the version of Solidity the code is compatible with.
Here: It compiles with Solidity version 0.8.5 and any version above it that doesn’t introduce breaking changes (i.e., up to but not including 0.9.0).
Why It Matters: Prevents unexpected issues from compiler version differences.
Contract Definition
contract MoodLogger {
Purpose: Declares a new smart contract named MoodLogger.
What It Is: A basic on-chain application that allows users to store and retrieve a mood string.
State Variable: moods
mapping(address => string) private moods;
Type: Mapping (dictionary-like structure)
Purpose: Maps each Ethereum address to a string (the user's mood).
Access: Marked private, meaning only functions inside the contract can read or write to it directl
Security Note: Although marked private, on-chain data can still be read publicly by advanced users (blockchain is transparent).
Function: setMood
function setMood(string memory mood) public {
moods[msg.sender] = mood;
}
Purpose: Lets the user save their current mood.
Input: _mood – the mood text (e.g., "happy", "stressed").
Scope: public, so anyone can call it.
Logic: Stores the mood string in the mapping, keyed to the caller’s address using msg.sender.
Function: getMood
function getMood() public view returns (string memory) {
return moods[msg.sender];
}
Purpose: Lets a user retrieve their own mood.
Return Type: A string stored in memory.
Scope: public view – anyone can call it, and it doesn’t change contract state (read-only).
Logic: Returns the mood string associated with the caller's address (msg.sender).
How the Code Works
Let’s break it down quickly:
mapping(address => string) private moods;
This creates a storage system that links each wallet address to a mood (string). It’s private, so it can’t be read directly from outside.function setMood(string memory _mood)
This function allows the current user (msg.sender) to store their mood.function getMood()
This function allows the user to read their own mood from the blockchain.
That’s all , just two functions and one mapping. But it’s enough to demonstrate how the state works in Solidity.
NB: A function is an action your smart contract can perform.Mapping is like a blockchain dictionary or storage locker. State refers to the permanent data stored in the contract.
Step-by-Step: Deploying on Remix + MetaMask
Step 4: Compile the Contract
Click the Solidity Compiler tab (left panel)
Make sure the compiler version matches ^0.8.5
Hit Compile MoodLogger.sol
You should see a green check mark if it compiles successfully.
Step 5: Connect MetaMask and Deploy
Click the Deploy & Run Transactions tab
Set Environment to: Injected Provider - MetaMask
Remix will ask to connect your wallet — approve it
Make sure MetaMask is on Sepolia or another testnet
Click Deploy
Approve the transaction in MetaMask
Boom. Your smart contract is now live on the testnet.
Step 6: Interact With the Contract
Once deployed, your contract will show up under Deployed Contracts in Remix.
To set your mood:
Expand the contract
In the setMood field, enter a word like energized
Click setMood
Confirm the transaction in MetaMask
To get your mood:
Click getMood
It’ll return whatever mood you last saved with your wallet
You just interacted with the blockchain , congrats!
Final Thoughts
The Mood Logger isn’t just a playful project . It's a hands-on way to understand how smart contracts work:
You learned how to use mappings to store per-user data
You saw how to interact with the contract through Remix and MetaMask
You deployed a real smart contract to a testnet
Not bad for your first day in Solidity!
Next, you can build on this: maybe store mood history, attach timestamps, or even allow emojis. The blockchain world is your playground.
Want to try it yourself?
Grab the full code and guide from GitHub .
Need help building your next smart contract? I’m just a message away.
Subscribe to my newsletter
Read articles from Job Akhidenor directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
