Ask It Simply
Build With AI · Advanced · Lesson C2

Your first smart contract in Remix

about 10 minutes. Level: On-chain. Nothing to install: Remix in your browser, using the Remix VM test chain with play money.

Education only. Not financial advice.

Education only. Not financial advice.

Watch the video

Lesson video, about 3 min 17 s. Captions are off by default. Press CC to turn them on. It starts muted. Press Sound to hear the lesson from the start. Press and hold the playing video (or hold the period key) to watch at 2x speed.
Show transcript

Welcome to Lesson C2. Before we start, this lesson is education only. It is not financial advice. Today you'll write your first smart contract, have Grok explain it, and run it on a test chain inside your browser. Nothing to install, and only play money.

So what's a smart contract? Ethereum dot org says, quote, "A 'smart contract' is simply a program that runs on the Ethereum blockchain." End quote. One language for writing them is called Solidity. Its docs say, quote, "Solidity is an object-oriented, high-level language for implementing smart contracts." End quote.

Let's open Remix in the browser. In the File Explorer, make a new file called Counter dot sol, and paste in the counter contract from the lesson page. It stores one number. One button adds one. Another subtracts one.

Now let's have Grok explain it. Paste the prompt from the lesson page, then the contract. We ask for a line by line explanation in plain words, what uint256 means, what require does, and what happens if we subtract at zero. Look for this: count stores a number, increment adds one, and decrement refuses to go below zero.

Back in Remix. Click the Solidity compiler icon, and press the Compile button. A green check means it compiled.

Now click the Deploy & Run icon. Under Environment, pick Remix VM. The Remix docs say, quote, "The Remix VM is a sandbox blockchain in the browser. Transactions do not require an approval to run." End quote. Press Deploy.

Under Deployed Contracts, open Counter. Press increment two times, then count. Two. Press decrement once. Count shows one. Now press decrement two more times. The second one fails, with the message Count is already zero. That's the require line doing its job.

One more thing. Don't write security code from scratch. OpenZeppelin calls its library, quote, "A library for secure smart contract development." End quote. It says, quote, "Build on a solid foundation of community-vetted code." End quote. Our tip: when you're ready for real projects, start from well-known building blocks like these.

Safety check. Ethereum dot org describes smart contracts as, quote, "running immutable logic based on code deployed on the blockchain." End quote. Immutable means it can't be changed. So a bug is hard to fix after launch. Our tip: keep your contracts on test networks or in the Remix VM while you learn.

Quick check. What's a smart contract? A program that runs on a blockchain. Was the ETH in the Remix VM real? No, it's play money. Why did the last decrement fail? The require line stops it below zero. Education only. Not financial advice. Next, in Lesson C3, you'll hunt for a bug with Grok.

What you'll learn

Step 1: What is a smart contract?

Ethereum.org says: "A 'smart contract' is simply a program that runs on the Ethereum blockchain." (Ethereum.org smart contracts)

One language for writing them is Solidity. Its docs say: "Solidity is an object-oriented, high-level language for implementing smart contracts." (Solidity docs)

Step 2: Paste the counter contract into Remix

  1. Open Remix in your browser.
  2. In the File Explorer, create a new file named Counter.sol.
  3. Paste this in:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

// A tiny practice contract. Test networks or the Remix VM only.
contract Counter {
    uint256 public count;          // the number we store

    function increment() public {  // add 1
        count += 1;
    }

    function decrement() public {  // subtract 1
        require(count > 0, "Count is already zero");
        count -= 1;
    }
}

Step 3: Ask Grok to explain it

Paste this into Grok, followed by the contract:

I'm a beginner. Explain this Solidity contract line by line in plain words.
What does "uint256" mean? What does "require" do? What happens if I call
decrement when count is 0? Keep it short. Here is the contract:

Look for: count stores a number, increment adds 1, and decrement refuses to go below zero with the message "Count is already zero".

Grok's real answer (our test run)

We ran this exact prompt through Grok (model grok-4.7) on Oct 30, 2026. Grok's answers change from run to run, so yours will differ. Quoted as Grok returned it, except where we mark [trimmed] and where we swapped dashes for commas to match our style.

This is a tiny counter. Anyone can add 1 or subtract 1, but it will not go below 0.

If you call decrement when count is 0, the require fails. The transaction reverts: nothing is saved, count stays 0, and you see "Count is already zero". In 0.8, subtracting from 0 would revert anyway; this check makes the reason clear.

Education only. Not financial advice.

Step 4: Compile and deploy on the test chain

  1. Click the Solidity compiler icon and press the Compile button.
  2. Click the Deploy & Run icon. Under Environment, pick Remix VM.
  3. Press Deploy.

The Remix docs say: "The Remix VM is a sandbox blockchain in the browser. Transactions do not require an approval to run." (Remix docs: Deploy & Run) Everything here is play money.

Step 5: Click the buttons

Under Deployed Contracts, open Counter. 1. Press increment two times, then press count. You should see 2. 2. Press decrement one time, then count. You should see 1. 3. Press decrement two more times. The second one fails with "Count is already zero".

We tested this exact contract on a local test chain on our own computer: it compiled, the count read 1 after two increments and one decrement, and calling decrement at zero was refused.

Step 6: Don't write security code from scratch

OpenZeppelin Contracts calls itself "A library for secure smart contract development." and says: "Build on a solid foundation of community-vetted code." (OpenZeppelin Contracts docs) Our tip: when you're ready for real projects, start from well-known building blocks like these instead of inventing your own.

Want more practice? CryptoZombies teaches Solidity with a game.

Check yourself

  1. What is a smart contract? (Answer: a program that runs on a blockchain)
  2. Was the ETH in the Remix VM real? (Answer: No. It's play money in your browser.)
  3. Why did the last decrement fail? (Answer: the require line stops count from going below zero)

Caution box Ethereum.org describes smart contracts as "running immutable logic based on code deployed on the blockchain." (Ethereum.org smart contract security) Immutable means it can't be changed, so a bug is hard to fix after launch. Our tip: keep your contracts on test networks or in the Remix VM while you learn. Education only. Not financial advice.

Builds on

Sources

Creator credits

Education only. Not financial advice.

Keep going