0% found this document useful (0 votes)
80 views32 pages

1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views32 pages

1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Ethereum was initially released in 2015.

Within two years of its release, it was ranked the second


best blockchain network, Bitcoin is the first. The Ethereum network acquired more global interest
when china stated that it is the best blockchain network ever created.

What is Ethereum?

Ethereum is a Blockchain network that introduced a built-in Turing-complete programming


language that can be used for creating various decentralized applications (also called Dapps). The
Ethereum network is fueled by its own cryptocurrency called ‘ether’.(ETH)
 The Ethereum network is currently famous for allowing the implementation of smart
contracts. Smart contracts can be thought of as ‘cryptographic bank lockers’ which
contain certain values.
 These cryptographic lockers can only be unlocked when certain conditions are met.
 Unlike bitcoin, Ethereum is a network that can be applied to various other sectors.
 Ethereum is often called Blockchain 2.0 since it proved the potential of blockchain
technology beyond the financial sector.
 The consensus mechanism used in Ethereum is Proof of Stakes(PoS), which is more
energy efficient when compared to that used in the Bitcoin network, that is, Proof of
Work(PoW). PoS depends on the amount of stake a node holds.

History of Ethereum

 2013: Ethereum was first described in Vitalik Buterin’s white paper in 2013 with the
goal of developing decentralized applications.
 2014: In 2014, EVM was specified in a paper by Gavin Wood, and the formal
development of the software also began.
 2015: In 2015, Ethereum created its genesis block marking the official launch of the
platform.
 2018: In 2018, Ethereum took second place in Bitcoin in terms of market capitalization.
 2021: In 2021, a major network upgrade named London included Ethereum
improvement proposal 1559 and introduced a mechanism for reducing transaction fee
volatility.
 2022: In 2022, Ethereum has shifted from PoW( Proof-of-Work ) to PoS( Proof-of-
State ) consensus mechanism, which is also known as Ethereum Merge. It has reduced
Ethereum’s energy consumption by ~ 99.95%.

Features of Ethereum
1. Smart contracts: Ethereum allows the creation and deployment of smart contracts.
Smart contracts are created mainly using a programming language called solidity.
Solidity is an Object-Oriented Programming language that is comparatively easy to
learn.
2. Ethereum Virtual Machine (EVM): It is designed to operate as a runtime environment
for compiling and deploying Ethereum-based smart contracts.
3. Ether: Ether is the cryptocurrency of the Ethereum network. It is the only acceptable
form of payment for transaction fees on the Ethereum network.
4. Decentralized applications (Daaps): Dapp has its backend code running on a
decentralized peer-to-peer network. It can have a frontend and user interface written in
any language to make calls and query data from its backend. They operate on Ethereum
and perform the same function irrespective of the environment in which they get
executed.
5. Decentralized autonomous organizations (DAOs): It is a decentralized organization
that works in a democratic and decentralized fashion. DAO relies on smart contracts for
decision-making or decentralized voting systems within the organization.

Type of Ethereum Accounts


Ethereum has two types of accounts: An externally owned account (EOA), and a Contract account.
These are explained as following below:
 Externally owned account (EOA): Externally owned accounts are controlled by
private keys. Each EOA has a public-private key pair. The users can send messages by
creating and signing transactions.
 Contract Account: Contract accounts are controlled by contract codes. These codes are
stored with the account. Each contract account has an ether balance associated with it.
The contract code of these accounts gets activated every time a transaction from an
EOA or a message from another contract is received by it. When the contract code
activates, it allows to read/write the message to the local storage, send messages and
create contracts.

How Does Ethereum Work?


Ethereum implements an execution environment called Ethereum Virtual Machine (EVM).
 When a transaction triggers a smart contract all the nodes of the network will execute
every instruction.
 All the nodes will run The EVM as part of the block verification, where the nodes will
go through the transactions listed in the block and runs the code as triggered by the
transaction in the EVM.
 All the nodes on the network must perform the same calculations for keeping their
ledgers in sync.
 Every transaction must include:
 Gas limit.
 Transaction Fee that the sender is willing to pay for the transaction.
 If the total amount of gas needed to process the transaction is less than or equal to the
gas limit then the transaction will be processed and if the total amount of the gas needed
is more than the gas limit then the transaction will not be processed the fees are still
lost.
 Thus, it is safe to send transactions with the gas limit above the estimate to increase the
chances of getting it processed.

Real-World Applications of Ethereum


 Voting: Voting systems are adopting Ethereum. The results of polls are available
publicly, ensuring a transparent fair system thus eliminating voting malpractices.
 Agreements: With Ethereum smart contracts, agreements and contracts can be
maintained and executed without any alteration. Ethereum can be used for creating
smart contracts and for digitally recording transactions based on them.
 Banking systems: Due to the decentralized nature of the Ethereum blockchain it
becomes challenging for hackers to gain unauthorized access to the network. It also
makes payments on the Ethereum network secure, so banks are using Ethereum as a
channel for making payments.
 Shipping: Ethereum provides a tracking framework that helps with the tracking of
cargo and prevents goods from being misplaced.
 Crowdfunding: Applying Ethereum smart contracts to blockchain-based crowdfunding
platforms helps to increase trust and information symmetry. It creates many possibilities
for startups by raising funds to create their own digital cryptocurrency.
 Domain names: Ethereum name service allows crypto users to buy and manage their
own domain names on Ethereum, thus simplifying decentralized transactions without
putting users to remember long, machine-readable addresses.

Benefits of Ethereum
 Availability: As the Ethereum network is decentralized so there is no downtime. Even
if one node goes down other computing nodes are available.
 Privacy: Users don’t need to enter their personal credentials while using the network
for exchanges, thus allowing them to remain anonymous.
 Security: Ethereum is designed to be unhackable, as the hackers have to get control of
the majority of the network nodes to exploit the network.
 Less ambiguity: The smart contracts that are used as a basis for trade and agreement on
Ethereum ensure stronger contracts that differ from the normal traditional contracts
which require follow-through and interpretation.
 Rapid deployment: On Ethereum decentralized networks, enterprises can easily deploy
and manage private blockchain networks instead of coding blockchain implementation
from scratch.
 Network size: Ethereum network can work with hundreds of nodes and millions of
users.
 Data coordination: Ethereum decentralized architecture better allocates information so
that the network participants don’t have to rely on a central entity to manage the system
and mediate transactions.

Drawbacks of Ethereum
 Complicated programming language: Learning solidity from programming smart
contracts on Ethereum can be challenging and one of the main concerns is the scarcity
of beginner-friendly classes.
 Volatile cryptocurrency: Ethereum investing can be risky as the price of Ether is very
volatile, resulting in significant gains as well as a significant loss.
 Low transaction rate: Bitcoin has an average transaction rate of 7TPS and Ethereum
has an average speed of 15 TPS which is almost double that of bitcoin but it is still not
enough.

Meta Mask

 MetaMask is a cryptocurrency wallet that enables users to store Ether and other ERC-20
tokens.
 The wallet can also be used to interact with decentralized applications, or dapps.

The decentralized internet, Web3, is built on a foundation of cryptocurrencies and decentralized


applications (dapps). But in order to use them, you need a user interface. Ideally, an elegant,
intuitive, easy to use interface.

MetaMask is one of the leading crypto wallets, and relies on browser integration and good design
to serve as one of the main gateways to the world of Web3, decentralized finance (DeFi) and NFTs.

What is MetaMask?

MetaMask is a browser plugin that serves as an Ethereum wallet, and is installed like any other
browser plugin. Once it's installed, it allows users to store Ether and other ERC-20 tokens, enabling
them to transact with any Ethereum address.

By connecting to MetaMask to Ethereum-based dapps, users can spend their coins in games, stake
tokens in gambling applications, and trade them on decentralized exchanges ( DEXs). It also
provides users with an entry point into the emerging world of decentralized finance, or DeFi,
providing a way to access DeFi apps such as Compound and PoolTogether.

How to get started using MetaMask

Though it might seem complicated to beginners, MetaMask is one of the simpler Ethereum wallets
and dapp browsers to use, and can be set up in a couple of minutes in most cases.

To use MetaMask, you will need either Chrome, a Chromium-based browser such as Brave, or
Firefox.

How to get started using MetaMask

Though it might seem complicated to beginners, MetaMask is one of the simpler Ethereum wallets
and dapp browsers to use, and can be set up in a couple of minutes in most cases.

To use MetaMask, you will need either Chrome, a Chromium-based browser such as Brave, or
Firefox.

Ethereum Account

An Ethereum account is an entity with an ether (ETH) balance that can send transactions on
Ethereum. Accounts can be user-controlled or deployed as smart contracts.

PREREQUISITES

To help you better understand this page, we recommend you first read through our introduction to
Ethereum.

ACCOUNT TYPES

Ethereum has two account types:

 Externally-owned account (EOA) – controlled by anyone with the private keys


 Contract account – a smart contract deployed to the network, controlled by code. Learn
about smart contracts

Both account types have the ability to:

 Receive, hold and send ETH and tokens


 Interact with deployed smart contracts

Key differences

Externally-owned

 Creating an account costs nothing


 Can initiate transactions
 Transactions between externally-owned accounts can only be ETH/token transfers
 Made up of a cryptographic pair of keys: public and private keys that control account
activities

Contract

 Creating a contract has a cost because you're using network storage


 Can only send transactions in response to receiving a transaction
 Transactions from an external account to a contract account can trigger code which can
execute many different actions, such as transferring tokens or even creating a new contract
 Contract accounts don't have private keys. Instead, they are controlled by the logic of the
smart contract code

AN ACCOUNT EXAMINED

Ethereum accounts have four fields:

 nonce – A counter that indicates the number of transactions sent from an externally-owned
account or the number of contracts created by a contract account. Only one transaction with a
given nonce can be executed for each account, protecting against replay attacks where signed
transactions are repeatedly broadcast and re-executed.
 balance – The number of wei owned by this address. Wei is a denomination of ETH and there
are 1e+18 wei per ETH.
 codeHash – This hash refers to the code of an account on the Ethereum virtual machine
(EVM). Contract accounts have code fragments programmed in that can perform different
operations. This EVM code gets executed if the account gets a message call. It cannot be
changed, unlike the other account fields. All such code fragments are contained in the state
database under their corresponding hashes for later retrieval. This hash value is known as a
codeHash. For externally owned accounts, the codeHash field is the hash of an empty string.
 storageRoot – Sometimes known as a storage hash. A 256-bit hash of the root node of a
Merkle Patricia trie that encodes the storage contents of the account (a mapping between 256-
bit integer values), encoded into the trie as a mapping from the Keccak 256-bit hash of the
256-bit integer keys to the RLP-encoded 256-bit integer values. This trie encodes the hash of
the storage contents of this account, and is empty by default.

(opens in a new tab)↗Diagram adapted from Ethereum EVM illustrated(opens in a new tab)↗
EXTERNALLY-OWNED ACCOUNTS AND KEY PAIRS

An account is made up of a cryptographic pair of keys: public and private. They help prove that a
transaction was actually signed by the sender and prevent forgeries. Your private key is what you use
to sign transactions, so it grants you custody over the funds associated with your account. You never
really hold cryptocurrency, you hold private keys – the funds are always on Ethereum's ledger.

This prevents malicious actors from broadcasting fake transactions because you can always verify the
sender of a transaction.

If Alice wants to send ether from her own account to Bob’s account, Alice needs to create a
transaction request and send it out to the network for verification. Ethereum’s usage of public-key
cryptography ensures that Alice can prove that she originally initiated the transaction request. Without
cryptographic mechanisms, a malicious adversary Eve could simply publicly broadcast a request that
looks something like “send 5 ETH from Alice’s account to Eve’s account,” and no one would be able
to verify that it didn’t come from Alice.

ACCOUNT CREATION

When you want to create an account most libraries will generate you a random private key.

A private key is made up of 64 hex characters and can be encrypted with a password.

Example:

fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036415f

Algorithm(opens in a new tab) ↗. You get a public address for your account by taking the last 20
The public key is generated from the private key using the Elliptic Curve Digital Signature

The following example shows how to use a signing tool called Clef(opens in a new tab) ↗ to generate
bytes of the Keccak-256 hash of the public key and adding 0x to the beginning.

Ethereum client, Geth(opens in a new tab) ↗. The clef newaccount command creates a new key pair
a new account. Clef is an account management and signing tool that comes bundled with the

and saves them in an encrypted keystore.

It is possible to derive new public keys from your private key but you cannot derive a private key
from public keys. This means it's vital to keep a private key safe and, as the name
suggests, PRIVATE.

You need a private key to sign messages and transactions which output a signature. Others can then
take the signature to derive your public key, proving the author of the message. In your application,
you can use a javascript library to send transactions to the network.

CONTRACT ACCOUNTS

Contract accounts also have a 42 character hexadecimal address:

Example:

0x06012c8cf97bead5deae237070f9587f8e7a266d
The contract address is usually given when a contract is deployed to the Ethereum Blockchain. The
address comes from the creator's address and the number of transactions sent from that address (the
“nonce”).

VALIDATOR KEYS

There is also another type of key in Ethereum, introduced when Ethereum switched from proof-of-
work to proof-of-stake based consensus. These are 'BLS' keys and they are used to identify validators.
These keys can be efficiently aggregated to reduce the bandwidth required for the network to come to
consensus. Without this key aggregation the minimum stake for a validator would be much higher.

More on validator keys.

A NOTE ON WALLETS

An account is not a wallet. An account is the keypair for a user-owned Ethereum account. A wallet is
an interface or application that lets you interact with your Ethereum account.

Smart contracts are tools that can automatically execute transactions if certain conditions are met

without requiring the help of an intermediary company or entity. They are often associated

with Ethereum, a blockchain that was designed to accommodate smart contracts, but the idea isn’t

restricted to any particular platform or network.

Whether obvious or not, intermediaries permeate our digital lives. Even simply sharing a cat photo

with friends online requires the services of an intermediary like Facebook or Twitter – a central

authority that doesn’t just manage the network, but also set the rules and enforce their violation. Smart

contracts make it possible to automate these digital tasks without needing a centralized entity to

manage and approve the transaction.

Smart contracts are made possible by blockchains, a network of computers that work together to

enforce rules on the network without requiring the help of an intermediary.

With conventional contracts, a document outlines the terms of a relationship between two parties,

which is enforceable by law. If one Party A violates the terms, Party B can take Party A to court for

not complying with the agreement. A smart contract fortifies such agreements in code so the rules are

automatically enforced without courts (or any third party) getting involved.
Ethereum, the world’s second-largest cryptocurrency by market cap, was created in 2013 specifically

for creating smart contracts. To date, it is the most popular platform for doing so.

Smart contracts aren't widely used outside of Ethereum, and some are skeptical they'll ever achieve

mainstream popularity as a way to manage transactions. Ethereum proponents, however, believe they

could eventually become the norm for executing and securing online relationships.

Hundreds of apps that use smart contracts are already up and running. Popular Ethereum

apps MakerDAO and Compound use smart contracts at their core for lending and allowing users to

earn interest.

First conceived in 1993, the idea of a "smart contract" was originally described by computer scientist

and cryptographer Nick Szabo as a kind of digital vending machine. In his famous example, he

described how users could input $1, and receive an item from a machine, in this case a snack or a soft

drink.
Smart contracts are the same in that with a certain input (the $1), the user should be able to expect a

certain outcome (the chosen drink).

In a simple example of an Ethereum smart contract, a user sends a friend 10 ether – the token native to

Ethereum – but requires that it can't be dispersed until after a certain date using a smart contract.

Why Ethereum smart contracts?

The world's first cryptocurrency, Bitcoin, was the first to support basic smart contracts, although they

are extremely limited in comparison with Ethereum. Each transaction is a smart contract because the

network will only approve of the transactions if certain conditions are met – that the user provides a

digital signature proving that they indeed own the cryptocurrency they claim to own. Only the owner

of a Bitcoin private key can produce such a digital signature.

By contrast, Ethereum replaces Bitcoin’s more restrictive language, replacing it with language that

allows developers to use the blockchain to process more than just cryptocurrency transactions. The

language is "Turing-complete," meaning it supports a broader set of computational instructions.

Without limits, programmers can write just about any smart contract they can think of.

While this has obvious advantages, it also means that, because novel smart contracts are less tested,

there is a higher chance of vulnerabilities. Ethereum has already seen millions of dollars of

losses from exploited vulnerabilities in smart contracts.

What can smart contracts be used for?

Some common ways of using smart contracts are:

 Multisignature accounts: Funds can only be spent when a required percentage of people

agree.
 Encoding financial agreements: Manage agreements between users. Say, if one person buys

insurance from an insurance company, the rules of when the insurance can be redeemed can

be programmed into a smart contract.

 Agreements based on the outside world: Pull in data from the outside world (financial,

political, or whatever) with the help of oracles.

 Provide third party: Similar to how a software library works, smart contracts can work with

other smart contracts in a chain.

 Storage: Store information about an application, such as domain registration information or

membership records. Storage in a blockchain like Ethereum is unique in that the data is

immutable and can't be erased.

How can smart contracts work together?

Smart contracts aren’t intended to be used in isolation. Some smart contracts are built to assist other

smart contracts.

When someone, say, places a simple bet on the temperature on a hot summer day via a smart contract,

it might trigger a chain reaction of contracts under the hood. One contract would use outside data to

determine the weather, and another contract could settle the bet based on the information it received

from the first contract when the conditions are met.

With this in mind, smart contracts form the building blocks for decentralized applications and even

whole companies, dubbed decentralized autonomous companies, which are controlled by smart

contracts rather than human executives.

How is a smart contract set up?

A developer can create a smart contract by writing a slab of code – spelling out the rules, such as that

10 ether can only be retrieved by Alice 10 years from now.


The developer then pushes the smart contract to the Ethereum network, which is what enforces the

contract – not allowing anyone to take the money unless they follow the exact rules in the code.

Thousands of computers from around the world then all have a copy of this smart contract.

How do I use a smart contract?

Anyone can use smart contracts if they have Ethereum's native token ether, which can be bought on

cryptocurrency exchanges.

Ethereum apps will usually provide instructions for how to use their specific app and underlying

smart contracts. A common method is to use an Ethereum wallet tool, such as Metamask, to send the

ether.

Users can use smart contracts for a range of use cases. Users can publish uncensorable posts to

microblogging apps or lend out money without an intermediary, using a variety of Ethereum apps.

Do smart contracts cost anything?

Getting thousands of computers across the world to validate smart contracts often isn't cheap, though,

as recent ballooning Ethereum fees highlight. The user must pay a fee, typically in ether (Ethereum’s

native token), to keep the network up and running. Fees go up when the network grows more

congested.

Are smart contracts legally enforced?

To many Ethereum advocates, smart contracts are intended to live outside of the legal system because

they are enforced automatically. If they work as they're supposed to, users won't need to go to a court

to settle conflicts.
That said, many wonder how these contracts would be treated under the current legal system. The

answer is complicated. One 2018 research paper from partners Stuart D. Levi and Alex B. Lipton

determined that U.S. law should recognize many smart contracts.

But, every country has a different legal approach to cryptocurrencies and blockchains, with some

more accepting of the new technology than others.

Are smart contracts the future?

Many developers, researchers, and even lawyers and doctors are excited about the promises of smart

contracts.

But it’s early days for smart contracts. While users of smart contracts don’t need to trust

intermediaries, users must trust that the code was written correctly, which is a big ask seeing as there

are still plenty of security issues. Many bug exploits have been unearthed over the years which

allowed bad actors to steal user funds. The hope is these issues will grow rarer as the code matures.

STEPS TO CREATE, TEST AND DEPLOY ETHEREUM SMART CONTRACT


Talk to our Consultant
Ever since Ethereum was introduced in the blockchain space with its presence in 2015, Vitalik
Buterin, a Canadian-Russian programmer, has brought forth new decentralized applications (dApps).
However, Ethereum’s success is significantly attributed to the implementation of smart contracts.

Many people believe that smart contracts are a new concept and were invented with the Ethereum

Blockchain Platform. But smart contracts date back to 1996 when computer scientist Nick Szabo

coined the term “smart contracts” and explained them as:

I call these new contracts “smart”, because they are far more functional than their inanimate paper-

based ancestors. No use of artificial intelligence is implied. A smart contract is a set of promises

specified in digital form, including protocols within which the parties perform on these promises.

His work later inspired other scientists and researchers, as well as Vitalik, who developed Ethereum.

Before we go deeper into the creation and deployment of the Ethereum smart contract, it is essential

to understand the Ethereum platform and how it works.


 Ethereum, as a Blockchain Platform for developing decentralized applications
 How Ethereum Blockchain Platform executes Smart Contracts?
 What is a Smart Contract?
 What is Solidity?
 Steps to develop an Ethereum Smart Contract
 Steps to test an Ethereum smart contract
 Tools and Technologies required for implementing Ethereum Smart Contracts
Ethereum, as a Blockchain Platform for developing decentralized applications

Blockchain platforms allow developers to create and run smart contracts. Ethereum is also one of the

blockchain platforms that can execute arbitrary code so that you can perform any program on

Ethereum.

The Ethereum Blockchain is a potential distributed infrastructure that facilitates you to complete

projects using smart contracts.


 Create your cryptocurrencies
Ethereum, you can create a tradable token that you can use as a new currency. Tokens created
with the Ethereum platform use a standard coin API to be compatible with any Ethereum
blockchain wallet.
 Develop virtual organizations
You can write a smart contract to build a blockchain-based organization. You can then add
more people to your organization and enable voting rules. Members of your organization can
vote and if it reaches the required number of votes, the smart contract executes automatically.
 Build dApps
Ethereum allows developers to develop secure and fault-tolerant decentralized apps that
eliminate intermediaries and offer transparency.
 Raise funds
You can also use Ethereum smart contracts for fundraising. With Ethereum, you can write a
smart contract and a deadline. In case you fail to accomplish the goal, all donations will
automatically be reimbursed to donors without disputes or commissions.
How Ethereum Blockchain Platform executes Smart Contracts

Before discussing how to create a smart contract on the Ethereum platform, you need to understand

the Ethereum blockchain and how it runs smart contracts.

So, let’s understand the execution environment first.


Ethereum Virtual Machine (EVM)

The purpose of EVM is to serve as a runtime environment for smart contracts built on Ethereum.

Consider it as a global supercomputer that executes all the smart contracts.

As the name indicates, Ethereum Virtual Machine is not physical but a virtual machine. The

functionality of EVM is restricted to virtual machines; for example, it cannot make delayed calls on

the internet or produce random numbers. Therefore, it is considered a simple state machine. Writing

programs in assembly language do not make any sense, so, Ethereum required a programming

language for the EVM.


Gas

In the Ethereum Virtual Machine, gas is a measurement unit used for assigning fees to each

transaction with a smart contract. Each computation happening in the EVM needs some amount of

gas. The more complex the computation is, the more the gas is required to run the smart contracts.

Transaction fee = Total gas used*gas price


Solidity

Solidity is a smart contract programming language on Ethereum. Developed on the top of the EVM, it

is similar to the object-oriented programming language that uses class and methods. It allows you to

perform arbitrary computations, but it is used to send and receive tokens and store states. When it

comes to syntax, Solidity is greatly influenced by C++, Python, and Javascript so that developers can

understand its syntax quickly.

It would be best to have a good understanding of Solidity programming language to efficiently write

an Ethereum Smart Contract.


What is a Smart Contract?

Smart Contracts are the business logic or a protocol according to which all the transactions on a

Blockchain happen. The smart contract’s general objective is to satisfy common contractual

conditions like creating its own token on ethereum. We need to develop smart contracts according to

which all the calculations on our token would happen.

It is a stand-alone script written in Solidity and compiled into JSON and deployed to a particular

address on the blockchain. Just like we can call a URL endpoint of a RESTful API to run some logic

through an HttpRequest, we can execute deployed smart contract similarly at a particular address by

entering the accurate data along with Ethereum to call the compiled and deployed Solidity function.

Smart contracts are deployed to the decentralized database for a fee proportional to the containing

code’s storage size. It can also be defined as a collection of code stored in the blockchain network,

defining conditions to which all parties within the contract should agree.

We will be sharing the example of Ethereum smart contract creation using the Solidity programming

language. So, it is first essential to understand what is Solidity.


What is Solidity?

Solidity is a Javascript-like language developed specifically for creating smart contracts. It is typed

statically and supports libraries, inheritance and complex user-defined types.

Solidity compiler converts code into EVM bytecode which is sent to the Ethereum network as a

deployment transaction.

FOR REFERENCE

Here’s a step-by-step guide to creating and deploying Ethereum Smart Contracts with Solidity

Installing Prerequisites

Meta-mask Chrome Extension

MetaMask acts both as an Ethereum browser and a wallet. It allows you to interact with smart

contracts and dApps on the web without downloading the blockchain or installing any software. You

only need to add MetaMask as a Chrome Extension, create a wallet and submit Ether.

Though MetaMask is currently available for Google Chrome browser, it is expected to launch for

Firefox too in the coming years.

Download MetaMask chrome extension before you start writing smart contracts.
Once it is downloaded and added as a Chrome extension, you can either import an already created

wallet or create a new wallet. You must have some ethers in your Ethereum wallet to deploy

Ethereum smart contract on the network.

Steps to develop an Ethereum Smart Contract

Step 1: Create a wallet at meta-mask

Install MetaMask in your Chrome browser and enable it. Once it is installed, click on its icon on the

top right of the browser page. Clicking on it will open it in a new tab of the browser.

Click on “Create Wallet” and agree to the terms and conditions by clicking “I agree” to proceed

further. It will ask you to create a password.

After you create a password, it will send you a secret backup phrase used for backing up and restoring

the account. Do not disclose it or share it with someone, as this phrase can take away your Ethers.
You should either write this phrase on a piece of paper securely or store it safely on an external

encrypted hard drive where no one could find it.

The next step is to ensure that you are in the “Main Ethereum Network.” If you find a checkmark next

to “Main Ethereum Network”, you are in the right place.

Step 2: Select any one test network

You might also find the following test networks in your MetaMask wallet:
 Robsten Test Network
 Kovan Test Network
 Rinkeby Test Network
 Goerli Test Network
The above networks are for testing purposes only; note that these networks’ ethers have no real value.

Step 3: Add some dummy Ethers to your wallet

In case you want to test the smart contract, you must have some dummy ethers in your MetaMask

wallet.

For example, if you want to test a contract using the Robsten test network, select it and you will find 0

ETH as the initial balance in your account.

To add dummy ethers, click on the “Deposit” and “Get Ether” buttons under Test Faucet.
LeewayHertz’s Ethereum Smart Contract Development
Automate your business processes with Ethereum Smart Contracts

CONSULT OUR EXPERTS


To proceed, you need to click “request one ether from the faucet,” and 1 ETH will be added to your

wallet. You can add as many Ethers you want to the test network.

For example, I have added 1 ETH in this scenario.


Once the dummy ethers are added to the wallet, you can start writing smart contracts on the Remix

Browser IDE in the Solidity programming language.

Step 4: Use editor remix to write the smart contract in Solidity

We will use Remix Browser IDE to write our Solidity code. The remix is the best option for writing

smart contracts as it comes with a handful of features and offers a comprehensive development

experience.

It is usually used for writing smaller-sized contracts. Remix’s features include:


 Warnings like gas cost, unsafe code, checks for overlapping variable names, whether
functions can be constant or not
 Syntax and error highlighting
 Functions with injected Web3 objects
 Static analysis
 Integrated debugger
 Integrated testing and deployment environment
 Deploy directly to Mist or MetaMask

Let’s start writing smart contract code by visiting https://remix.ethereum.org.

Step 5: Create a .sol extension file

Open Remix Browser and click on the plus icon on the top left side, next to the browser to create

a .sol extension file.

Step 6: A sample smart contract code to create ERC20 tokens

ERC20.sol is a standard template for ERC20 tokens.


pragma solidity ^0.4.0;

import "./ERC20.sol";

contract myToken is ERC20{

mapping(address =>uint256) public amount;

uint256 totalAmount;

string tokenName;

string tokenSymbol;

uint256 decimal;

constructor() public{

totalAmount = 10000 * 10**18;

amount[msg.sender]=totalAmount;

tokenName="Mytoken";

tokenSymbol="Mytoken";

decimal=18;

function totalSupply() public view returns(uint256){

return totalAmount;

function balanceOf(address to_who) public view


returns(uint256){

return amount[to_who];

function transfer(address to_a,uint256 _value) public

returns(bool){

require(_value<=amount[msg.sender]);

amount[msg.sender]=amount[msg.sender]-_value;

amount[to_a]=amount[to_a]+_value;

return true;

Select a version of the compiler from Remix to compile the solidity Ethereum smart contract code.

Step 7: Deploy your contract

Deploy the smart contract at the Ethereum test network by pressing the deploy button at the Remix

window’s right-hand side.

Wait until the transaction is complete.

After the transaction commits successfully, the address of the smart contract would be visible at the

right-hand side of the remix

window.

At first, all the ERC20 tokens will be stored in the wallet of a user who is deploying the smart

contract.

To check the tokens in your wallet, go to the metamask window, click add tokens, enter the smart

contract address and click ok. You would be able to see the number of tokens there.
Steps to test an Ethereum smart contract
1. Try to run all your smart contract methods like transfer, total supply, and balance(in the above
smart contract example). These methods are present at the right-hand side of the remix
window and you can run all the processes from there itself.
2. Try to transfer some tokens to other ethereum wallet addresses and then check the balance of
that address by calling the balance method.
3. Try to get total supply by running the total supply method.
Steps to deploy Ethereum Smart Contracts
1. To make your smart contract live, switch to the main ethereum network at metamask
2. Add some real ethers.
3. Now again, deploy your smart contract using remix as mentioned in the above steps.
4. When a smart contract is deployed successfully, visit http://www.etherscan.io and search your
smart contract address there. Select your smart contract.
5. Now you need to verify your smart contract here, click “verify the contract.”
6. Copy your smart contract code and paste it at Etherscan. Select the same compiler version
that you selected at remix to compile your code.
7. Check “optimization” to Yes, if you had selected optimization at remix; otherwise, select No.
8. Click Verify.
9. It will take a few minutes and your smart contract will be live if no issue occurs.
10. You can now run your smart contract methods at Etherscan.
Tools and Technologies required for implementing Ethereum Smart Contracts
 Truffle
t is an Ethereum development framework that allows developers to write and test smart
contracts. Written in JavaScript, Truffle contains a compiler for the Solidity programming
language. Truffle Contract is a JavaScript library that allows importing of compiled smart
contracts.
 Web3.js
It is an Ethereum JavaScript API that interacts with the Ethereum network via RPC calls.
 Visual Studio Code
A functional code editor.
 Ganache CLI
It is an Ethereum remote procedure call client within the Truffle framework that is also known
as TestRPC.
 Parity
It is a secure and fast Ethereum client for handling Ethereum accounts and tokens.
 Node.js
It is a javascript runtime environment used for server-side programming. Node.js is required
to test the Ethereum smart contract’s functionality while ensuring its secure and proper
operation. You need to install a package manager, for example, Yarn along with Node.js.

MetaMask is a type of cryptocurrency wallet that is used to interact with user interfaces of
different web3 applications(For example, Mist browsers, DApps) and the regular web (For
example, Google Chrome, Mozilla Firefox, websites). Its function is to inject a JavaScript library
called web3.js into the namespace of each page your browser loads. Web3.js is written by the
Ethereum core team. MetaMask is mainly used as a plugin in the web browser. Let’s walk through
the steps to install it on Google Chrome.
Step 1: Go to Chrome Web Store Extensions Section.
Step 2: Search MetaMask.
Step 3: Check the number of downloads to make sure that the legitimate MetaMask is being
installed, as hackers might try to make clones of it.

Step 4: Click the Add to Chrome button.


Step 5: Once installation is complete this page will be displayed. Click on the Get Started button.

Step 6: This is the first time creating a wallet, so click the Create a Wallet button. If there is already
a wallet then import the already created using the Import Wallet button.
Step 7: Click I Agree button to allow data to be collected to help improve MetaMask or else click
the No Thanks button. The wallet can still be created even if the user will click on the No
Thanks button.
Step 8: Create a password for your wallet. This password is to be entered every time the browser is
launched and wants to use MetaMask. A new password needs to be created if chrome is uninstalled
or if there is a switching of browsers. In that case, go through the Import Wallet button. This is
because MetaMask stores the keys in the browser. Agree to Terms of Use.

Step 9: Click on the dark area which says Click here to reveal secret words to get your secret
phrase.
Step 10: This is the most important step. Back up your secret phrase properly. Do not store your
secret phrase on your computer. Please read everything on this screen until you understand it
completely before proceeding. The secret phrase is the only way to access your wallet if you forget
your password. Once done click the Next button.
Step 11: Click the buttons respective to the order of the words in your seed phrase. In other words,
type the seed phrase using the button on the screen. If done correctly the Confirm button should turn
blue.
Step 12: Click the Confirm button. Please follow the tips mentioned.
Step 13: One can see the balance and copy the address of the account by clicking on the Account
1 area.
Step 14: One can access MetaMask in the browser by clicking the Foxface icon on the top right. If
the Foxface icon is not visible, then click on the puzzle piece icon right next to it.
Ethereum is a decentralized blockchain platform that establishes a peer-to-peer network that securely
executes and verifies application code, called smart contracts. Smart contracts allow participants to
transact with each other without a trusted central authority. Transaction records are immutable,
verifiable, and securely distributed across the network, giving participants full ownership and
visibility into transaction data. Transactions are sent from and received by user-created Ethereum
accounts. A sender must sign transactions and spend Ether, Ethereum's native cryptocurrency, as a
cost of processing transactions on the network.

Benefits of building on Ethereum

Ethereum offers an extremely flexible platform on which to build decentralized applications using the
native Solidity scripting language and Ethereum Virtual Machine. Decentralized application
developers who deploy smart contracts on Ethereum benefit from the rich ecosystem of developer
tooling and established best practices that have come with the maturity of the protocol. This maturity
also extends into the quality of user-experience for the average user of Ethereum applications, with
wallets like MetaMask, Argent, Rainbow and more offering simple interfaces through which to
interact with the Ethereum blockchain and smart contracts deployed there. Ethereum’s large user base
encourages developers to deploy their applications on the network, which further reinforces Ethereum
as the primary home for decentralized applications like DeFi and NFTs. In the future, the backwards-
compatible Ethereum 2.0 protocol, currently under development, will provide a more scalable
network on which to build decentralized applications that require higher transaction throughput.

Use cases

Decentralized Finance (DeFi)

DeFi is a network of financial applications built on top of blockchain networks. It is different from
existing financial networks because it is open and programmable, operates without a central authority,
and enables developers to offer new models for payments, investing, lending, and trading. By using
smart contracts and distributed systems, customers can easily build secure decentralized financial
applications. For example, DeFi companies are already offering products that enable peer-to-peer
lending and borrowing, earning interest on cryptocurrency holdings, trading via decentralized
exchanges, and much more. Some popular DeFi platforms include Compound, Aave, UniSwap, and
MakerDAO.

Non-Fungible Tokens (NFTs)

NFTs are unique and indivisible digital tokens that are useful for proving the provenance of rare
assets, both digital and tangible. For example, NFTs can be used by an artist to tokenize their work
and ensure that their work is unique and belongs to them. The ownership information is recorded and
maintained on the blockchain network. NFTs are also gaining popularity in the gaming industry
because they allow interoperability between gaming platforms. For instance, the first NFT project on
Ethereum was CryptoKitties, which enabled customers to collect digital cat collectibles backed using
NFTs. Gods Unchained is a card game that gives players full ownership of their in-game items using
NFTs. NFTs are gaining popularity as more companies look to tokenize assets and provide users with
tamper-proof lineage information about their assets.

You might also like