SolidityIn

Solidity 101: Writing Your Very First Smart Contract in 20 Minutes

October 28, 2026 · admin · Uncategorized

Step into Web3 development without installing a single tool. In this quick hands-on guide, you will write, compile, and deploy an Ethereum smart contract from scratch.

Smart contracts are simply programs stored on a blockchain that run when predetermined conditions are met. Solidity is the primary programming language used to write these contracts on the Ethereum blockchain and Ethereum Virtual Machine (EVM)-compatible networks like Polygon, Arbitrum, and Avalanche.

The best part? You don’t need to configure Node.js, install command-line tools, or pay real cryptocurrency to build your first contract. By using Remix, an in-browser Ethereum development environment, you can build and test everything inside your browser in under 20 minutes.

Minute 0–3: Setting Up Remix IDE

Instead of setting up local developer environments like Hardhat or Foundry, we’ll start with the industry-standard sandbox for learning: Remix IDE.

  1. Open your browser and navigate to remix.ethereum.org.
  2. Close any welcome modals. On the left sidebar, click the File Explorer icon (the top folder icon).
  3. Inside the contracts folder, click the New File icon.
  4. Name the file MyFirstContract.sol (all Solidity files end with the .sol extension).

Minute 4–10: Writing the Code

Paste the following code into your editor. We will build a simple “Digital Memo” contract that allows anyone to read a message, but lets only the contract deployer (the owner) change it.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract MyFirstContract {
// State variables stored permanently on the blockchain
string private memo;
address public owner;
// Event emitted when the memo changes
event MemoUpdated(string newMemo, address updatedBy);
// Runs once when the contract is deployed
constructor(string memory initialMemo) {
memo = initialMemo;
owner = msg.sender;
}
// Read function: Free to call (does not consume gas)
function readMemo() public view returns (string memory) {
return memo;
}
// Write function: Costs gas, modifies the blockchain state
function updateMemo(string memory newMemo) public {
require(msg.sender == owner, "Only the owner can update the memo");
memo = newMemo;
emit MemoUpdated(newMemo, msg.sender);
}
}

Minute 11–14: Understanding the Building Blocks

Let’s dissect what each part of this code does:

1. License & Pragma

  • // SPDX-License-Identifier: MIT: Specifying open-source licensing is standard practice in Ethereum to prevent compiler warnings.
  • pragma solidity ^0.8.20;: Tells the compiler to use version 0.8.20 or newer, but not 0.9.0 or higher.

2. State Variables

  • string private memo;: Stores a string permanently on the blockchain storage. Setting it to private means other contracts cannot read it directly (though data on a public blockchain is always publicly visible if inspected).
  • address public owner;: Holds an Ethereum address. Declaring it public automatically generates a hidden “getter” function so anyone can read who the owner is.

3. Constructor & Global Variables

  • constructor(string memory initialMemo): Runs automatically, exactly once, when the contract is deployed.
  • msg.sender: A built-in global variable containing the Ethereum wallet address of whoever called the current function (in the constructor, it’s the deployer).

4. View vs. State-Changing Functions

  • readMemo() is marked as view: It only reads data and does not modify blockchain state. View calls are free; they cost zero gas when invoked by external users.
  • updateMemo(...) modifies storage and does not have the view keyword. Calling this function generates a transaction, requires an Ethereum signature, and costs gas.
  • require(...): A guard statement. If the condition evaluates to false, execution halts, all changes are reverted, and unused gas is refunded.

Minute 15–16: Compiling Your Contract

Before a smart contract can run on the EVM, it must be compiled into bytecode.

  1. Click the Solidity Compiler icon on the left sidebar (looks like the Solidity ‘S’ logo).
  2. Ensure the Compiler version matches your pragma (e.g., 0.8.20 or compatible).
  3. Click the blue button: Compile MyFirstContract.sol.
  4. A green checkmark will appear over the compiler icon indicating a successful compilation.

Minute 17–20: Deploying and Testing

Now, let’s deploy your contract to a temporary sandbox blockchain running right inside your browser.

  1. Click the Deploy & Run Transactions icon (the Ethereum icon with an arrow).
  2. Under Environment, keep the default: Remix VM (Cancun). This simulates a local Ethereum network with pre-funded fake test accounts (each has 100 fake ETH).
  3. Locate the Deploy dropdown input next to the orange “Deploy” button.
  4. Enter your starting message into the field (e.g., "Hello, Web3!").
  5. Click Deploy.

Interact with your deployed contract:

Scroll down in the left panel to Deployed Contracts and expand your contract. You will see several buttons:

  • Blue Buttons (Read Operations): Click readMemo. It will immediately output "Hello, Web3!" without prompting for a transaction or gas.
  • owner: Click this to see the address that deployed the contract. Notice it matches your currently selected account at the top of the panel.
  • Orange Buttons (Write Transactions): Type a new message into the updateMemo box (e.g., "Decentralized future") and click the button.

Now, click readMemo again. The returned text has updated to your new value! In the bottom console, you can expand the transaction log to view the emitted MemoUpdated event.

Bonus: Testing the Security Check

Remember this line in your contract?

require(msg.sender == owner, "Only the owner can update the memo");

Let’s verify it actually protects your contract:

  1. Go to the Account dropdown at the top of the Deploy tab and select a different account from the list.
  2. Try entering a message in updateMemo and clicking the orange button.
  3. Check the Remix console at the bottom. The transaction will fail, throwing the exact revert message: “Only the owner can update the memo”.

Congratulations! What’s Next?

In just 20 minutes, you have learned the fundamentals of Solidity, written an access-controlled smart contract, compiled it, deployed it to a simulated EVM, and verified its state changes and access controls.

To continue your journey toward becoming a Web3 developer, consider exploring these next steps:

  • Testnets: Connect MetaMask to Remix and deploy your contract to the Ethereum Sepolia testnet using free testnet ETH.
  • Frameworks: Graduate from Remix to professional local development frameworks like Foundry or Hardhat.
  • Standards: Learn standard tokens by building an ERC-20 (fungible token) or an ERC-721 (NFT) contract using OpenZeppelin libraries.

Tags: , , ,