Build · Lesson 10 of 14

Your first smart contract

About 15 minutes · On a computer

You're going to write a tiny contract that stores a message, deploy it to the Remix practice chain, and change the message yourself. No wallet needed for this part.

  1. Create the file

    In Remix, click Files in the left bar. Click the Create button, choose New file, type MyFirstContract.sol and press Enter. The empty file opens in the editor.

  2. Paste the code

    Copy this code and paste it into the file.

    MyFirstContract.sol
    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.24;
    
    contract MyFirstContract {
      string public message = "Hello, Blockskool!";
    
      function setMessage(string calldata newMessage) external {
          message = newMessage;
      }
    }
  3. Compile it

    Press Ctrl + S (Cmd + S on a Mac), or click the Compile button above the editor. When it works, a green tick appears on the Compile icon in the left bar.

    Compiling turns your code into something Ethereum can run.

  4. Deploy it

    Click Deploy in the left bar. Check that Environment says Remix VM, that's the practice chain. Make sure MyFirstContract is selected (it says Compiled next to it), then click the big Deploy button.

  5. Read the message

    Remix switches to the Deployed Contracts tab and shows your contract with its functions. Next to message (it has a blue dot), click Call. You should see Hello, Blockskool! appear under it.

  6. Change it

    Find setMessage (it has an orange dot). Type your own message in its box, for example Ayubowan from Kandy!, then click Transact. The terminal at the bottom logs your transaction with a green tick.

  7. Read it again

    Click Call next to message again. It shows your text. You just changed data on a blockchain. 🎉

Before you move on

Tick these off as you go.