paint-brush
How to Simply Deploy a Smart Contract on Ethereumby@invoblox
970 reads
970 reads

How to Simply Deploy a Smart Contract on Ethereum

by Ryan JasonSeptember 28th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This article takes you through all the steps you need to deploy a smart contract during Ethereum software development. A smart contract is a software program that resides on the blockchain. It is a collection of. data and functions(https://ethereum.org/en/developers/docs/smart-contracts/)__ (code) Once a smart. contract is deployed, it creates an instance on the. Ethereum network. The process of deployment is performed by sending a transaction with a bytecode. This is the second approach in which smart contracts will be deployed on public.

Company Mentioned

Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - How to Simply Deploy a Smart Contract on Ethereum
Ryan Jason HackerNoon profile picture

Are you creating a blockchain solution?


Creating and deploying a smart contract is an important process. Once deployed, it becomes available to the Ethereum network. This article takes you through all the steps you need to deploy a smart contract during Ethereum software development.


Before that, let’s discuss smart contracts a bit.

What is a Smart Contract?


A Smart contract is a software program that resides on the blockchain. It is a collection of data and functions (code) that stays at a specific address on the Ethereum blockchain. Smart contracts define rules and conditions just like any regular contract and run automatically via code. Once a smart contract is deployed, it creates an instance on the Ethereum network. The process of deployment is performed by sending a transaction with a bytecode.


Deploying a Smart Contract on Local Network vs Ethereum Network


The method of deploying a smart contract on the local network is different from the one on the Ethereum network. On a local network, an emulator eg. Ganache-cli is used. It processes and executes all the functionalities automatically. Users do not need to manually track the gas amount or worry about security as transactions are made on the local test network.  On the other hand, when it comes to deploying a smart contract on the Ethereum network, users have to ensure some considerations.


Make sure that your Ethereum network has some ether in it before you deploy a smart contract because the deployment process acts as a transaction and needs some gas to execute. Usually, transactions on the Ethereum network take 15 seconds to 15 minutes. Local and Ethereum networks have one thing in common, both use Web3 to establish a connection between js application and the blockchain network. For this, a node is created that connects to the Ethereum network. Infura is a public API that can be used to create a node instead of creating it on your own.


Simply sign up on Infura and create a new project. Change the endpoint and save the URL to any location of your choice. After this, you won’t need to install a full node.


Steps to Deploy Smart Contract on Ethereum


Whether you are working on a public or a private Ethereum blockchain or in the process of your Ethereum DApp development, deploying smart contracts is an important step. You need to take care of many dependencies and tools that support Ethereum environments.


Follow the steps below to deploy your smart contract.


  1. Install all necessary tools and dependencies


We would need some basic tools to get started. Assuming that you are using any of the following operating systems.**
**

  • Windows
  • Mac OS X
  • Linux


Now download Node.js (version 8.9.4 or above). Run the following Truffle command to run the Ethereum client. It provides support for standard JSON RPC API.


npm i -g truffle


  1. Create smart contract


For Ethereum smart contract development in Solidity, you can use the OpenZeppelin library that helps you ensure security and minimize risks. OpenZeppelin has a built-in implementation of ERC standards.


Similarly, you can use Remix integrated development environment (IDE) that acts as a tool to write smart contracts. It is a web-based DApp that you can access without installing any tool.


  1. Deploy


We will look at three different approaches to deploying smart contracts.


3.1. On a personal blockchain using Ganache

3.2. On a public test network i.e. Rinkeby

3.3. On Ethereum mainnet


So let’s look at each one by one.


3.1.  On Personal Blockchain using Ganache


To deploy smart contracts on the local blockchain, we will use Ganache. It allows you to run, test, and execute smart contracts and manage blockchain operations.


  1. Download Ganache on your desktop
  2. Open Remix IDE in the browser. Click on the “+” icon and write the filename
  3. Write code to test and compile it
  4. Once the compilation is complete, open Ganache on your desktop and click on ‘Quickstart Ethereum’
  5. Now you have 10 default accounts on your blockchain network that is hosted at the local RPC server (HTTP://127.0.0.1:7545)
  6. Go to the Deploy section in your browser and select Web3 Provider from the drop-down menu
  7. Enter HTTP://127.0.0.1:7545 in Web3 Provider Endpoint and click on the ‘Deploy’ button
  8. Now expand the contract and click on the get_output() function to get the output of your smart contract
  9. To see your transactions, open Ganache -> Transactions


3.2.  On a Public Test Network i.e. Rinkeby


This is the second approach in which smart contracts will be deployed on a public test network using the Geth and Solidity compiler on Rinkeby.  Solidity is the Ethereum programming language for smart contracts.


  1. Install solc (Solidity compiler) using npm install -g solc. It helps you create opcodes that Ethereum Virtual Machine (EVM) can translate.
  2. Install Node.js
  3. Install Geth using Mac or Windows Geth installations. It is a command line interface (CLI) to run a full Ethereum node. It offers a number of interfaces including JSON RPC server, CLI subcommands, and console
  4. Install CLI from the Ethereum Command line tools webpage
  5. Start writing the code for your smart contracts and save it
  6. Open the terminal window and compile the code in Application Binary Interface (ABI) and bytecode to deploy on the blockchain. Display contents of files
  7. Create an account on Rinkeby testnet. You can see information such as coin base address and data directory on the console
  8. To deploy a smart contract from Geth, open an account using your passphrase, and set up ABI and bytecode using information displayed on the console


3.3.  On Ethereum Mainnet


The third approach is to deploy smart contracts on the Ethereum mainnet using the following tools.


  • Web3js: It offers a range of libraries that allow you to establish a connection with an Ethereum node using IPC, HTTP, or WebSocket
  • Truffle: It is a testing framework and development environment to deploy smart contracts for blockchains using EVM.
  • Testrpc: It is a blockchain emulator that allows you to interact with the blockchain without any overheads. It also allows you to instantiate a fixed amount of Ether, recycle or reset it


To deploy a smart contract on the actual Ethereum network, you would need to have Ether in your account. There are two types of Ethereum accounts. First is ‘Contract account’ which is totally smart contract based and is controlled by code. The other is ‘EOA’ in which people join the network.


  1. Install Web3js, Truffle, and testrpc
  2. Open testrpc and run an instance. From eth-lightwallet, take the information of public and private keys and update it in your config.js file
  3. To deploy smart contracts, we will use Truffle. Keep in mind that you just have some ether in your Ethereum account for the deployment process
  4. Open the terminal, go to your Truffle directory and run the command: “truffle deploy“
  5. A smart contract will be deployed and you will get its address


I hope this article was useful enough to help you deploy your smart contracts on the Ethereum blockchain.


Most of the time businesses or startups look for some Ethereum development services instead of hiring an in-house team and providing them with all the resources and equipment. If you are also looking for one, I would suggest InvoBlox. It offers top-class blockchain development services at incredibly affordable prices. Deployment of smart contracts is quite handy if you identify the dependencies and tools required for the different natures of Ethereum blockchain environments.