Don’t want to install stuff to get started creating smart contracts on the Ethereum blockchain? Use Ethereum remix to create and test your smart contracts! In this post we go over the basic functionalities of remix so you can get started fast.

For a local setup for developing smart contracts on the Ethereum blockchain read this previous post on Ethereum Development. For a more in depth documentation of the remix IDE go here.

Go to remix here and take a look at your smart contract IDE. The menu is located at the far left of the screen. We are going to cover the intentions of all of the six menu items (below the remix icon).

Smart Contract

The first menu item is the File Explorer where you edit your smart contracts.

remix file explorer tab - ETHEREUM REMIX

As you can see I already created a smart contract in the file Message.sol. We are going to skip the details of the solidity language for now and just provide the contract.

pragma solidity ^0.5.11;

contract Message {
    string public message = "Hello world!";
    
    function setMessage(string memory _message) public {
        message = _message;
    }
}

The code shouldn’t be hard to understand. We have a public message, this message can be read by anyone that has access to the blockchain. The message has an initial value and can be set to another message with the setMessage function.

Build and Run

Now we want to see our basic contract in action. First off we need to compile our code. In the second menu item we can choose the compiler version, the language and the auto compile option.

remix compiler tab - ETHEREUM REMIX

We already saw the green checkmark indicating a successful build. Now type some nonsense in your contract and see that it signals the compilation error in the contract, on top of the menu item and at the bottom of the compiler tab.

In the third menu item we can run our compiled on a test blockchain. There are a lot of options here but we focus on the essentials for now. When you click on Account you see we got five test accounts with all 100 ether. In the middle we can choose a smart contract to deploy, select Message.sol.

remix run tab - ETHEREUM REMIX

When you deploy our contract notice that the account balance dropped from the initial 100 ether. This is because deploying a smart contract on the blockchain costs ether. At the bottom we can now get our initial message and set a different message with the given buttons.

remix contract functions section - ETHEREUM REMIX

Note that setting the message costs ether while reading is without costs. This is basic blockchain mechanics for writing to the blockchain is done via transactions (bundled in blocks) which are evaluated for a fee. Transactions can be seen by anyone with a blockchain explorer for free (for ethereum go here). You can see these transactions appearing in remix below your contract code.

remix blockchain output 1024x477 - ETHEREUM REMIX

Clicking the arrow allows you to see the details of the transaction, for example the gas needed to execute the transaction (for more on gas watch this video).

Clicking the Debug button will open another menu item for debugging. This will be out of scope for this post but is very useful to analyse errors of your contract.

Check and Test

So we have some code that works as desired at a first glance. But we want to make sure we didn’t miss flaws in our code. Remix provides static code analysis out of the box in the fourth menu item.

remix static analysis section - ETHEREUM REMIX

We see all the checks that we would like to run and the Auto run option so we don’t forget to run the checks.

Furthermore we want to automate the functional tests that we did earlier to verify that the contract works. We can write unit tests to ensure this. Let’s give an example.

pragma solidity ^0.5.11;

import "remix_tests.sol"; // this import is automatically injected by Remix.
import "./Message.sol";

contract MessageTest {
   
    Message messageContract;
    function beforeAll () public {
       messageContract = new Message();
    }
    
    function checkInitialMessage () public {
        Assert.equal(messageContract.message(), "Hello world!", "Should return initial value");
    }
    
    function checkMessageCanBeChanged () public {
        messageContract.setMessage("Hello Sybren Boland IT");
        Assert.equal(messageContract.message(), "Hello Sybren Boland IT", "Message should be changed");
    }
}

We can run the tests in yet another menu tab. All in the green! So we can deploy the contract with confidence to the Ethereum blockchain.

remix unit testing tab - ETHEREUM REMIX

The last menu tab is the Plugin Manager with additional functionality that you can explore on your own.

Hopefully you can now start writing en testing your own smart contracts using Ethereum Remix. Happy mixing!