DEV Community

Khaleb O'Brien
Khaleb O'Brien

Posted on

Deploy a Smart Contract via Remix

Smart contracts - just another pinch of salt sprinkled on the blockchain ecosystem.

There're simply programs stored on a blockchain that run when predetermined conditions are met.

This guide will put you through on how to write a simple smart contract using RemixIDE and deploy to Polygon Mumbai Testnet.

Remix is a Ethereum-focused IDE: an online platform to develop and deploy smart contracts. To start building a smart contract, click on New File and name it HelloWorld.sol

RemixIDE - https://remix.ethereum.org

Hello Smart Contract!
Copy and paste the Smart Contract code provided below into the newly created HelloWorld.sol file.

    // Specifies that the source code is for a version
    // of Solidity greater than 0.5.10
    pragma solidity ^0.5.10;

    // A contract is a collection of functions and data (its state)
    // that resides at a specific address on the Ethereum blockchain.
    contract HelloWorld {

        // The keyword "public" makes variables accessible from outside a contract
        // and creates a function that other contracts or SDKs can call to access the value
        string public message;

        // A special function only run during the creation of the contract
        constructor(string memory initMessage) public {
            // Takes a string value and stores the value in the memory data storage area,
            // setting `message` to that value
            message = initMessage;
        }

        // A publicly accessible function that takes a string as a parameter
        // and updates `message`
        function update(string memory newMessage) public {
            message = newMessage;
        }
    }
Enter fullscreen mode Exit fullscreen mode

Compile Smart Contract

  • Go to the Solidity Compiler tab (below the search button)

  • Select compiler version to 0.5.10

  • Now, compile HelloWorld.sol

  • After successful compilation, it will show a green tick mark on the Compiler tab button

  • Now, We have to deploy our smart contract on Polygon Network. For that, we have to connect to the Web3 world which can be accomplished by using any of the services like Metamask, Brave, Portis etc. We will be using Metamask in this tutorial. Please follow this guide to set up a Metamask Account.

  • Open Metamask. Click on the network dropdown menu (set to Ethereum Mainnet by default) and click on Add Network button.

-- Network: Polygon Mumbai Testnet
-- New RPC URL: https://rpc-mumbai.maticvigil.com
-- Chain ID: 80001
-- Currency Symbol: MATIC
-- Block Explorer URL: https://mumbai.polygonscan.com/

  • Go ahead and click Save

  • Copy your wallet address from Metamask by clicking over your account name.

  • Head over to Faucet and request test MATIC - you will need this pay for gas on Polygon network. Select Mumbai as the network and MATIC Token as the token in the faucet.

  • Now, let's deploy the Smart Contract on Polygon Network

  • Select Injected Provider Metamask in the Environment dropdown and your contract.

  • Accept the Connect request received in MetaMask. If the popup doesn't open by default, you can also try manually launching the MetaMask extension

  • Once MetaMask is connected to Remix, the Deploy transaction would generate another MetaMask popup that requires transaction confirmation. Simply confirm the transaction!

Congratulations! You have successfully deployed the HelloWorld Smart Contract. You can start interacting with your Smart Contract. Check the deployment status at https://mumbai.polygonscan.com/.

Top comments (0)