In this tutorial, we'll explore the structure and functionality of a simple Solidity smart contract named "Walkthrough". This walkthrough is designed for beginners to understand how smart contracts operate on the Ethereum blockchain.
📜 The Walkthrough Contract — Full Source
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Walkthrough {
string public password;
uint8 public infoNum = 42;
string public theMethodName = "The method name is method7123949.";
bool private cleared = false;
// constructor
constructor(string memory _password) {
password = _password;
}
function info() public pure returns (string memory) {
return "You will find what you need in info1().";
}
function info1() public pure returns (string memory) {
return 'Try info2(), but with "hello" as a parameter.';
}
function info2(string memory param) public pure returns (string memory) {
if (keccak256(abi.encodePacked(param)) == keccak256(abi.encodePacked("hello"))) {
return "The property infoNum holds the number of the next info method to call.";
}
return "Wrong parameter.";
}
function info42() public pure returns (string memory) {
return "theMethodName is the name of the next method.";
}
function method7123949() public pure returns (string memory) {
return "If you know the password, submit it to authenticate().";
}
function authenticate(string memory passkey) public {
if (keccak256(abi.encodePacked(passkey)) == keccak256(abi.encodePacked(password))) {
cleared = true;
}
}
function getCleared() public view returns (bool) {
return cleared;
}
}
Here’s the logical flow a user should follow when interacting with the contract:
- Call info() → directs to info1()
- Call info1() → suggests info2("hello")
- Call info2("hello") → reveals infoNum
- Call infoNum() → reveals 42
- Call info42() → provides theMethodName
- Call theMethodName() → provides method7123949
- Call method7123949() → instructs to use authenticate()
- Call authenticate(password) → sets cleared to true
- Call getCleared() → confirms authentication
⏱️ Estimated time:
- 5 minutes to read
- 15–20 minutes if you follow along step-by-step in Remix
🛠️ How to Deploy This Contract Using Remix
-
Go to Remix IDE
-
Create a New File
- In the left sidebar, click the “File explorer” icon, you can find "FILE EXPLORER" panel
- Click the “Create new file” icon in the "FILE EXPLORER" panel to create a new file
- Name it Walkthrough.sol
- Paste the Contract into the main editor
-
Compile the Contract
- Click the “Solidity compiler” tab (third from top) on the left sidebar
- Confirm that the compiler version matches (0.8.x)
- Click the “Compile Walkthrough.sol” button
-
Deploy the Contract
- Click the ‘Deploy & Run Transactions’ tab (fourth icon: Ethereum logo) to open the ‘DEPLOY & RUN TRANSACTIONS’ panel
- At the top of the 'DEPLOY & RUN TRANSACTIONS' panel, set the Environment to 'Remix VM (Cancun)'
- Provide Constructor Argument such as "some_password" (including the quotes!), and click "Deploy" button
- Alternatively, click the down arrow to reveal a field labeled string _password, and provide "some_password" (including the quotes!) and click "transact" button
-
Run/Interact with the contract
- Scroll down in the panel to see the deployed contract instance
- Expand the Contract by clicking the little arrow beside the deployed contract to view its functions
- Run the methods info(), info1(), info2("hello"), and so on.
- If you run the method getCleared() and receive true, you’ve successfully completed the walkthrough.
🔗 Reference
This walkthrough is based on a smart contract challenge from Ethernaut, a Web3 security game created by OpenZeppelin.
You can view the original level here:
👉 The ethernaut - Hello Ethernaut
✍️ Written by Yuanyan Wu — software engineer learning smart contract security, one contract at a time. If you'd like to see more Solidity walkthroughs like this — or want a deeper dive into smart contract vulnerabilities — let me know in the comments.