Solidity Basics Part 2Solidity Basics (Part 2) — Arrays, Mappings & Structs (Upgrading the Web3 Journey Logger)Yesterday we took our first real steps into Solidity: variables, functions, and a simple Web3JourneyLogger contract that stored a single note on-chain. Today we’re going to upgrade that tiny contract into something closer to how real dApps manage data.
This is Day 27 of the 60‑Day Web3 journey, still in Phase 3: Development. The goal for today is to understand how Solidity handles collections of data : arrays, mappings, and structs and then use them together to build a multi‑entry, multi‑user on-chain journal.
1. Why we need more than simple variablesStoring a single dayNumber and note is cute, but it doesn’t scale.
Real smart contracts usually need to:
In normal programming, you’d reach for arrays, dictionaries, and objects. In Solidity, you get very similar tools:
We’ll see each one separately, then combine them into a better Web3 Journey Logger.
2. Arrays: storing ordered listsAn array in Solidity is an ordered list of elements of the same type.
2.1 Fixed vs dynamic arraysThere are two main kinds of arrays:
This always has exactly 5 elements. You cannot grow or shrink it.
This can grow as you push new elements to it.
For most dApp use cases, you’ll use dynamic arrays.
2.2 Basic operations on dynamic arraysHere’s a tiny example:
uint256[] public daysLearned;function addDay(uint256 _day) public {Key points:
Arrays are great for ordered lists, but they aren’t efficient for lookups like “give me the entry for this address”. For that, we use mappings.
3. Mappings: key–value storage on-chainA mapping is like a dictionary or hash map: you give it a key, and it gives you a value.
3.1 Basic mapping syntaxThe general form:
mapping(KeyType => ValueType) public myMapping;Example:
mapping(address => uint256) public entryCountByUser;This mapping says: “for each address, store a uint256 count”.
If you do:
entryCountByUser[msg.sender] = 5;then entryCountByUser[msg.sender] will later return 5.
3.2 Important mapping quirksMappings have some important properties:
They behave like infinite default dictionaries.
They are not iterable.
Because of these quirks, mappings are best used for “given a key, fetch the value” patterns, like:
A struct lets you define your own data shape by grouping fields together.
4.1 Defining and using a structExample struct:
struct Entry {You can use it like this:
Entry public latestEntry;function setLatestEntry(uint256 _day, string calldata _note) public {Structs are especially powerful when combined with arrays and mappings.
5. Upgrading the Web3 Journey LoggerLet’s upgrade yesterday’s contract to support multiple entries per user and multiple users.
5.1 New designWe want:
Helper functions to:
This leads to a pattern like:
mapping(address => Entry[]) public entriesByUser;Which you can read as: “for each address, store an array of Entry structs”.
5.2 Full upgraded contractHere’s a full version of an upgraded Web3JourneyLoggerV2:
// SPDX-License-Identifier: MITA few things to notice:
This contract is no longer just a single note; it’s a tiny, multi‑user journaling dApp backend.
6. Deploying V2 and testing itYou can deploy Web3JourneyLoggerV2 using the same Remix + Sepolia flow from yesterday:
Once deployed:
Ask a friend to connect their wallet and call addEntry too. Now your contract is tracking multiple learners and their progress on-chain.
7. Why arrays + mappings + structs matterThese three tools — arrays, mappings, and structs — are the backbone of almost every serious Solidity contract:
By understanding how to combine them, you’re no longer just “deploying example contracts” — you’re modeling real-world data structures on-chain.
Tomorrow, we can build on this by adding more features like:
For now, if you deploy Web3JourneyLoggerV2 on Sepolia, share your contract address — let’s see how many on-chain learning journals we can spin up.
Further readingSolidity Basics (Part 2) — Arrays, Mappings & Structs (Upgrading the Web3 Journey Logger) was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.