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.
Create the file
In Remix, click Files in the left bar. Click the Create button, choose New file, type
MyFirstContract.soland press Enter. The empty file opens in the editor.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; } }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.
Deploy it
Click Deploy in the left bar. Check that Environment says Remix VM, that's the practice chain. Make sure
MyFirstContractis selected (it says Compiled next to it), then click the big Deploy button.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 seeHello, Blockskool!appear under it.Change it
Find
setMessage(it has an orange dot). Type your own message in its box, for exampleAyubowan from Kandy!, then click Transact. The terminal at the bottom logs your transaction with a green tick.Read it again
Click Call next to
messageagain. It shows your text. You just changed data on a blockchain. 🎉
Before you move on
Tick these off as you go.