Skip to main content

Using Remix

A Hello World style starter project. Deploys a smart contract with a message, and renders it in the front-end. You can change the message using the interact panel!

This dapp implements a "Hello World" style application that echoes a message passed to the contract to the front end. This tutorial is intended to be followed using the online IDE available at Remix IDE.

Setting up Remix IDE

  • Remix IDE - an online IDE to develop smart contracts.

  • If you’re new to Remix, You’ll first need to activate two modules: Solidity Compiler and Deploy and Run Transactions.

  • search for 'Solidity Compiler' and 'Deploy and Run Transactions' plugins in the plugin tab in Remix

    RemixIDE_Step1
  • Activate the two plugins

    RemixIDE_Step1
  • Select Solidity Environment

    RemixIDE_Step1
  • RemixIDE_Step2Go to File Explorers, And Create a new file , Name it HelloWorld.sol
  • Copy/Paste the Smart contract below into the newly created file HelloWorld.sol

The smart contract

HelloWorld.sol
// 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;
}
}

The first line, pragma solidity ^0.5.10 specifies that the source code is for a Solidity version greater than 0.5.10. Pragmas are common instructions for compilers about how to treat the source code (e.g., pragma once).

A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. The line string public message declares a public state variable called message of type string. You can think of it as a single slot in a database that you can query and alter by calling functions of the code that manages the database. The keyword public automatically generates a function that allows you to access the current value of the state variable from outside of the contract. Without this keyword, other contracts have no way to access the variable.

The constructor is a special function run during the creation of the contract and cannot be called afterward. In this case, it takes a string value initMessage, stores the value in the memory data storage area, and sets message to that value.

The string public message function is another public function that is similar to the constructor, taking a string as a parameter, and updating the message variable.

Compile Smart Contract

  • Go to Solidity Compiler
  • Select Compiler Version to 0.5.10
  • Now, Compile HelloWorld.sol
  • After Successful Compilation, it will show
  • Now, We have to deploy our smart contract on ETM/P Network. For that, we have to connect to web3 world, this can be done by using any of the services like Metamask, Brave, Portis etc. We will be using Metamask. Please follow this tutorial to setup a Metamask Account.
  • Open Metamask and select Custom RPC from the networks dropdown
RemixIDE_Step1
  • Put in a Network name - “ETM/P Testnet”

  • In URL field you can add the URL as "https://testnet-rpc.etm.network"

  • Enter the Chain ID: 80001

  • (Optional Fields) Symbol: "maticmum" and Block Explorer URL: "https://testnet.etmscan.network"

    RemixIDE_Step1
  • Go ahead and click save

  • Copy your address from Metamask

    RemixIDE_Step1
  • Head over to Faucet and request test ether - you will need this pay for gas on ETM/P. Select 'Mumbai' as the network and 'ETM/P Token' as the token in the faucet

  • Now, let's Deploy the Smart Contract on ETM/P Network

  • Select Injected Web3 in the Environment dropdown and your contract

RemixIDE_Step1
  • Accept the Connection Request!
RemixIDE_Step1
  • Once Metamask is connected to Remix, the ‘Deploy’ transaction would generate another metamask popup that requires transaction confirmation.
RemixIDE_Step1
**Congratulations!** You have successfully deployed HelloWorld Smart Contract. Now you can interact with the Smart Contract. Check the deployment status here: https://testnet.etmscan.network
RemixIDE_Step1
# **Verifying your Contracts on ETM/PScan**

The first and foremost step is to flatten the solidity contract into a single file.

Flatten your solidity contract

Install truffle-flattener or sol-merger

Flatten using command

sol-merger \"./contracts/*.sol\" ./build

Verifying on ETM/PScan

Navigate to your contract's polygonscan page and then click verify and publish

  • Select Solidity (Single File) in compiler type
  • Select appropriate compiler version
  • Choose the license type of your contract

Onto the next section, paste your flattended contract here.

If you had enabled optimization then adjust the optimization section accordingly.

Constructor arguments should have been filled in automatically, if not, they can be retrieved from the trailing bytes of the deployment transaction, they resemble something like 000000000000000000000000a6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa

That's it, you are done. 🎉