Building with Solidity
Basic Contract Walkthrough
This lesson demonstrates a complete smart contract example - a workshop attendance tracker that showcases core Solidity concepts including structs, mappings, events, access control modifiers, and constructor functions in a practical, real-world context.
Contract Overview
We’ll use a simple participation tracking contract, ideal for workshops or attendance-based dApps. It allows users to check in with a name, stores the record, and emits an event.
Concept Recap: WorkshopContract
Concept | What It Does |
| Groups related data into a single type. In this case, |
| Stores key-value pairs, in this case, |
| Emits onchain logs. |
| Restricts function access. |
| Runs once at deployment. Sets the contract owner using |
| Enforces rules like ensuring a name is provided and preventing duplicate check-ins. |
| Global variable that records the current time. Used to log when someone checks in. |
| Global variable that identifies who is interacting with the contract. |
Contract Ownership and Constructors
In Solidity, the constructor function runs once when the contract is deployed. It's often used to assign the contract owner, who can then be given special privileges using modifiers.
The msg.sender global variable represents the address that deployed the contract. By saving it, we can restrict certain functions to only this address later.
Access Control with Modifiers
A modifier is reusable logic that runs before a function executes. Common use: access restriction.
The _ keyword is a placeholder for the function body. Any function using onlyOwner will first check the condition above.
Usage:
Join our Telegram