Writing your First Smart Contract using Remix

Photo by Art Rachen on Unsplash

Writing your First Smart Contract using Remix

What is a Smart Contract?

A smart contract, as defined by Ethereum, is just a program that runs on the Ethereum blockchain.

Much like traditional contracts, they can be used as digital forms of agreement. Executing a smart contract essentially creates a transaction on the blockchain and hence, these transactions are trackable and irreversible.

We can write smart contracts using the Solidity programming language. We'll use the Remix IDE which saves a lot of time in setup because it is online.

You can start working with Remix by following this link.

Open up the Remix IDE for the first time and it looks something like this. You'll have to agree to some stuff and then go through a first-time tour of the options in the sidebar.

The sidebar contains 4 options, the first one is the file structure, which shows you all the different files and folders in your workspace.

You then have a search button, a tab to choose the Solidity compiler (you can change versions here) and a tab where you can deploy your smart contracts.

Writing your first Smart Contract

Create a new file with the name FirstContract.sol. You might've noticed that we use the sol extension, and you guessed it right, it is the extension we use for Solidity files.

I'm on this version of the Solidity compiler. You might have to change your compiler to this one if you want the same results.

Let's write our first contract now.

pragma solidity ^0.8.0;

contract FirstContract {    
    string name = "";

    function setName(string memory _newName) public {
        name = _newName;

We can deploy this contract on a JavaScript VM for now.