Deploy Smart Contract Using Remix


Back to All Posts

How to Deploy Smart Contract Using Remix

This tutorial will guide you through the steps to deploy an smart contract using the Remix IDE, one of the most popular tools for writing and deploying Solidity contracts.

Prerequisites

Before you start, ensure that you have the following ready:

  1. MetaMask wallet extension installed in your browser.
  2. Sufficient ETH (test ETH for testnets or real ETH for mainnet) in your MetaMask wallet to cover gas fees.
  3. Basic knowledge of Solidity.

Step 1: Open Remix IDE

Go to the Remix IDE using a browser like Chrome or Firefox. The Remix interface is an online Solidity IDE where you can write, compile, and deploy smart contracts directly from your browser.

Step 2: Write Your Smart Contract

  1. In the Remix IDE, click on the File Explorer tab on the left panel and click the + button to create a new file.
  2. Name your file with a .sol extension (for example, MyToken.sol).
  3. Write or paste your smart contract code into the editor. Below is a simple example of an ERC-20 token contract in Solidity:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract MyToken is ERC20 {
    constructor(uint256 initialSupply) ERC20("MyToken", "MTK") {
        _mint(msg.sender, initialSupply);
    }
}

This contract creates an ERC-20 token called "MyToken" with the symbol "MTK" and mints an initial supply of tokens to the contract deployer's address.

Step 3: Compile the Smart Contract

  1. After writing the contract, click on the Solidity Compiler tab (the "Solidity" icon) on the left panel.
  2. Select the appropriate compiler version (e.g., 0.8.x to match your contract's pragma version) from the dropdown.
  3. Click Compile MyToken.sol. Ensure there are no errors in the compilation.

Step 4: Connect MetaMask to Remix

  1. Open MetaMask in your browser and ensure you are connected to the correct network (e.g., Ropsten, Rinkeby, or Mainnet).
  2. In Remix, click on the Deploy & Run Transactions tab (the Ethereum icon) on the left panel.
  3. In the "Environment" dropdown, select Injected Provider - MetaMask. This will automatically connect Remix to MetaMask.

You should now see your MetaMask account address in the Account field.

Step 5: Deploy the Smart Contract

  1. In the Deploy & Run Transactions tab, under "Contract," ensure that your contract MyToken is selected from the dropdown list.
  2. Enter the required constructor parameters if your contract has them (for the example ERC-20 contract, you need to input the initial supply in wei, e.g., 1000000000000000000000 for 1000 tokens with 18 decimals).
  3. Click Deploy.

MetaMask will prompt you to confirm the transaction and display the estimated gas fees. Click Confirm to proceed with the deployment.

Step 6: Verify Deployment

Once the transaction is confirmed, your contract will be deployed on the Ethereum network. You can verify this by checking the Deployed Contracts section in Remix or viewing the transaction details on Etherscan (or the respective block explorer for testnets like Ropsten or Rinkeby).

The deployed contract address will be shown under the Deployed Contracts section. You can interact with the contract directly from this section by calling any of its public or external functions.

Step 7: Interact with the Deployed Contract (Optional)

After deployment, you can interact with the contract via the Remix interface:

  1. In the Deployed Contracts section, expand your deployed contract.
  2. You will see buttons for all the functions defined in your contract. For example, you can call the totalSupply() or balanceOf() function to check the token balance.

This process can be used for any Solidity contract, whether it's an ERC-20 token, NFT, or other types of contracts. You can now use your contract in decentralized applications or integrate it into your DApp.