February 20, 2018 Blockchain, Blockchain Tutorials, Smart Contracts

Best Way to Deploy Your Smart Contracts


There are various ways to deploy Ethereum based smart contracts, some popular options are listed here:

  1. Use migrations of Truffle framework.
  2. Use Ethereum wallet and MetaMask.
  3. Using Remix IDE and MetaMask.

I prefer the last option, and would suggest the readers of this blog to follow the same, as it is most optimised as far as gas consumption is concerned and it can also be used to debug contracts.

In this tutorial we will deploy a sample contract, which is initially available on Remix, using MetaMask, on Ropsten test network.

MetaMask Setup:

MetaMask Setup

Step 1
Download the MetaMask extension. There are various options for browsers with MetaMask compatibility, however in this tutorial we use Chrome extension as reference.

Following is a tutorial you should follow to understand MetaMask and set up your own wallet on it, it is quite outdated but it is the perfect way for you to get the gist of things and get you started with MetaMask.

Step 2
You will need to create a suitable password, which will be used to encrypt and create a seed phrase.

Step 3
Keep the seed phrase somewhere secure and don’t share it with anyone, it can be used to retrieve your wallet.

Step 4
Change your network by clicking on Main Network and switch to Ropsten Test Network.

available networks

Step 5
Click on Buy, to get some free Ropsten Ethers.


Step 6
Go to the Ropsten test faucet and request some Ethers, they will be mined in some time and will be added to your Ethereum account on MetaMask.

test faucet

Step 7
In some time your account will look like this, and you will be ready to deploy your first test contracts on Ropsten.

mined ethers

Using Remix IDE to deploy contracts:

Open the Remix IDE and you will see a pre-compiled contract file, namely ballot.sol. We will use this contract to understand how the deployment using Remix works.

deployment options

There are three kinds of options available for deployment in Remix:

  1. JavaScript VM:
    It helps you deploy your contracts in a JavaScript environment made available by remix, it gives you five Ethereum accounts with a balance of 100 Ethers each to deploy and test your contracts.
  2. Injected Web3 :
    This will help you connect your MetaMask account to Remix and use the network you’re on for deployment. You can choose among “Ropsten”, “Rinkeby” and “Mainnet”. Ropsten and Rinkeby should be used for testing your contracts before deploying them.
  3. Web3 Provider:
    You can use some explicit Web3 provider or can integrate it on your localhost and use it.

We will be using Injected Web3 as it is the easiest and widely used. So choose injected Web3 and proceed:

Step 1:
You will see your Ropsten account in the “Account” section of “Run” Subhead. This represents your current MetaMask account which will be used for all the required transactions. You can create more accounts on MetaMask and switch between them to connect different accounts to Remix. Please note that only one MetaMask account can be connected to remix at a time.

Step 2:
Enter number of proposals, which is a parameter required by constructor of Ballot contract and click create. You will see a MetaMask pop-up like the following:

confirm tx

This pop-up asks for a confirmation for the transaction you’re just about to create. I’ll explain the details mentioned and how to manipulate them one by one:

Gas Limit:
MetaMask calculates the maximum amount of gas that can be consumed by a transaction and displays it here, this amount of gas will be sent with the transaction, in case all the gas is not consumed during the transaction, remaining gas will return back to your account.

Gas Price:
It calculates the latest price which is being used in the Ropsten test network, it depends on amount of traffic within Ropsten Network. You can increase it for faster results.

Max Transaction Fee:
It represent the maximum estimated mining fee for the transaction. Is an estimate of costs in USD and Ethers.

Max Total:
Sub total of all the costs in USD/Ethers.

Step 3:
Once you submit your transaction, you can track it’s status in MetaMask or Ropsten Etherscan.

tx processing

Step 4:
Once the transaction is processed and is added to a block then you will see the contract at the bottom of “Run” section in Remix, as follows:

deployed contract

You can see all the public functions and state variables of the contract here. Blue represents that a function/variable is constant and it won’t consume any gas during execution. Constant functions are those which does not result in value change of state variables, and thus don’t consume any gas. Similarly Red represents a function which will consume gas and should be carefully used, when you use it a MetaMask pop-up to confirm transaction will appear. You can set the required parameters and submit your transaction. There are some other functions which accept Ethers, and can be used to send Ethers to a contract, it is of a darker red colour. You can specify the value and the unit you will be using in the “Value” section labelled under “Gas Limit”.

Understanding contract deployments is very necessary, and nascent developers make a lot of mistakes in this part leading to huge deployment costs and cumbersome testing mechanisms. This blog is a guide for beginners to avoid those mistakes and enjoy happy development/deployment within solidity.


Share this article!

Leave a comment