Deploying Your First Smart Contract with Remix

Smart Contracts are written in Solidity, a statically-typed programming language designed for Ethereum and other EVM-compatible chains. This tutorial uses Remix, a browser-based IDE that requires minimal setup.

1.Open Remix IDE: Navigate to Remix.

2.Create a New Contract: In the workspace, create a new file with the ".sol" extension, e.g., "MyFirstContract.sol".

3.Code a Basic Contract:

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

contract MessageContract {
    string private message;

    function writeMessage(string calldata newMessage) public {
        message = newMessage;
    }

    function readMessage() public view returns (string memory) {
        return message;
    }
}

Remix automatically compiles the contract when saved. Ensure there are no compilation errors.

4.Compile Manually (Optional): Click the "Advanced Configurations" tab and select the Solidity version london.

5.Deploy the Contract: Click the "Deploy" icon logo (it looks like an Ethereum logo with an arrow pointing to the right).

6.Configure Deployment:

  • Select the basic contract.

  • Under "Environment," choose "Injected Provider - MetaMask."

  • Connect Remix to MetaMask.

7.Initiate Deployment: Click "Deploy" and confirm the MetaMask transaction.

8.Interact With Your Contract:

Step1: After deployment, find your contract under "Deployed Contracts."

Step2: Expand the contract and call writeMessage by entering a message and clicking the button.

Step3: Confirm the MetaMask transaction.

Step4: Read the Message:

Click the blue "readMessage" button to read the on-chain message.

Now you've successfully deployed and interacted with your first smart contract using Remix and MetaMask.

Last updated

#234: update CP

Change request updated