Remix

How to compile, deploy and interact with a solidity smart contract on chain

Remix is an open-source, web-based integrated development environment (IDE) for writing, compiling, deploying, and debugging Solidity smart contracts on the Ethereum blockchain. It provides a user-friendly interface with tools for testing, debugging, and interacting with smart contracts directly from the browser.

Open Remix at https://remix.etherium.org

Deploying your first smart contract

By default you can find the HelloWorld.sol contract in the file explorer under contracts.

Compile it using the third tab.

You can deploy it using the fourth tab. You will need to select the injected provider environment and make sure your metamask is connected to the right network and account.

Deploy the contract, it should open a window for signature (notice the fees in XRP).

Once deployed successfully you can interact with it by scrolling down tab 4.

Creating other contracts

Create the following contract in remix, give it the name counter.sol

counter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
    uint256 private counter;

    constructor() {
        counter = 0;  // Initialize counter to 0
    }

    function incrementAndGet() public returns (uint256) {
        counter += 1;  // Increment the counter
        return counter;  // Return the updated counter value
    }

    function getCounter() public view returns (uint256) {
        return counter;  // Return the current counter value
    }
}

Compile the new contract using the third tab.

Deploy the contract using the fourth tab.

You can now interact with the counter smart contract:

  • send a transaction to increment it, this will trigger a transaction to sign in Metamask

  • read the current value (notice how this is free)

To go further you can explore the key concepts behind the simple banking contract we deploy in the banking app.

Last updated