Smart Contracts With Ethereum
Smart Contracts With Ethereum
INTRODUCTION
1
1.2 What is Ethereum?
Ethereum is an open-source, public, blockchain-based distributed computing platform and
operating system featuring smart contract (scripting) functionality. It supports a modified version
of Nakamoto consensus via transaction-based state transitions. Ether is a token whose blockchain
is generated by the Ethereum platform. Ether can be transferred between accounts and used to
compensate participant mining nodes for computations performed. Ethereum provides a
decentralized virtual machine, the Ethereum Virtual Machine (EVM), which can execute scripts
using an international network of public nodes. The virtual machine's instruction set, in contrast to
others like Bitcoin Script, is thought to be Turing-complete. "Gas", an internal transaction pricing
mechanism, is used to mitigate spam and allocate resources on the network.
Ethereum was proposed in late 2013 by Vitalik Buterin, a cryptocurrency researcher and
programmer. Development was funded by an online crowdsale that took place between July and
August 2014.
2
the pre-defined rules are met, the agreement is automatically enforced. The smart contract code
facilitates, verifies, and enforces the negotiation or performance of an agreement or transaction. It
is the simplest form of decentralized automation. It is a mechanism involving digital assets and
two or more parties, where some or all of the parties deposit assets into the smart contract and the
assets automatically get redistributed among those parties according to a formula based on certain
data, which is not known at the time of contract initiation. smart contracts eliminate the need for
trusted third parties The term smart contract is a bit unfortunate since a smart contract is neither
smart nor are they to be confused with a legal contract. A smart contract can only be as smart as
the people coding taking into account all available information at the time of coding. While smart
contracts have the potential to become legal contracts if certain conditions are met, they should
not be confused with legal contracts accepted by courts and or law enforcement. However, we will
probably see a fusion of legal contracts and smart contracts emerge over the next few years as the
technology becomes more mature and widespread and legal standards are adopted.
Would you enter into a contract with someone whom you’ve never met? Would you agree to
lend money to some farmer in Ethiopia? Would you become an investor in a minority-run
newspaper in a war zone? Would you go to the hassle of writing up a legal binding contract for a
$5 purchase over the internet? For most people the answer would be no, as the transaction costs
for these examples exceed the value transferred. Smart contracts radically reduce transaction costs.
Auto enforceable code – whether on the protocol level or on the application level – standardizes
transaction rules, thus reducing the transaction costs of:
• reaching an agreement,
3
• formalization, and
• enforcement.
A smart contract can formalize the relationships between people, institutions and the assets they
own. The transaction rulesets (agreement) of the smart contract define the conditions – rights and
obligations – to which the parties of a protocol or smart contract consent. It is often predefined,
and agreement is reached by simple opt-in actions. This transaction rule set is formalized in digital
form, in machine-readable code (formalization). These rights and obligations established in the
smart contract can now be automatically executed by a computer or a network of computers as
soon as the parties have come to an agreement and met the conditions of the agreement
(enforcement) (Glatz).
The concept of a smart contract is not new. However, Blockchain seems to be the catalyst for smart
contract implementation. The most primitive form of a smart contract is a vending machine. The
rules of a transaction are programmed into a machine. You select a product by pressing a number
related to that product, insert the coins, the machine acts as a smart contract checking wether you
inserted enough money, If yes, the machine is programmed to eject the product, and if you inserted
too much money, it will also eject the change. If you didn’t insert enough money, or if the machine
ran out of the money, you will get your change back. Automatic vending machines not only slashed
transaction costs by making human vendors obsolete, but they also expanded service, offering 24/7
availability instead of limited opening hours of a kiosk.
1.3.2 Characteristics of a Smart Contract
Smart contracts are capable of tracking performance in real time and can bring tremendous
cost savings. Compliance and controlling happen on the fly. In order to get external information,
a smart contract needs information oracles, which feed the smart contract with external
information.
Smart Contracts are
• Self-verifying
• Self-executing
• Tamper resistant
Smart Contracts can
• Turn legal obligations into automated processes.
• Guarantee a greater degree of security.
• Reduce reliance on trusted intermediaries.
• Lower transaction costs.
1.4 Introduction to Solidity
4
was influenced by C++, Python and JavaScript and is designed to target the Ethereum Virtual
Machine (EVM).
Solidity is statically typed, supports inheritance, libraries and complex user-defined types among
other features. With Solidity you can create contracts for uses such as voting, crowdfunding, blind
auctions, and multi-signature wallets. When deploying contracts, you should use the latest released
version of Solidity. This is because breaking changes as well as new features and bug fixes are
introduced regularly. We currently use a 0.x version number [to indicate this fast pace of change]
(https://semver.org/#spec-item-4).
Use npm for a convenient and portable way to install solcjs, a Solidity compiler. The solcjs
program has fewer features than the ways to access the compiler described further down this page.
The Using the Command line Compiler documentation assumes you are using the full-featured
compiler, solc. The usage of solcjs is documented inside its own repository.
Note: The solc-js project is derived from the C++ solc by using Emscripten which means that both
use the same compiler source code. solc-js can be used in JavaScript projects directly (such as
Remix). Please refer to the solc-js repository for instructions.
web3.js is a collection of libraries which allow you to interact with a local or remote
ethereum node, using a HTTP or IPC connection. The following documentation will guide you
through installing and running web3.js, as well as providing a API reference documentation with
examples.
The web3.js library is a collection of modules which contain specific functionality for the ethereum
ecosystem.
5
1.7 Introduction to Ganache
Ganache is a personal blockchain for Ethereum development you can use to deploy
contracts, develop your applications, and run tests. It is available as both a desktop application as
well as a command-line tool (formerly known as the TestRPC). Ganache is available for Windows,
Mac, and Linux.
Ganache CLI, part of the Truffle suite of Ethereum development tools, is the command line version
of Ganache, your personal blockchain for Ethereum development. Ganache CLI uses ethereumjs
to simulate full client behavior and make developing Ethereum applications faster, easier, and
safer. It also includes all popular RPC functions and features (like events) and can be run
deterministically to make development a breeze. Looking for TesIf you came here expecting to
find the TestRPC, you're in the right place! Truffle has taken the TestRPC under its wing and made
it part of the Truffle suite of tools. From now on you can expect better support along with tons of
new features that help make Ethereum development safer, easier, and more enjoyable. Use
ganache-cli just as you would testrpc.
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser,
making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and
accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on GitHub.
6
CHAPTER 2
EXISTING SYSTEM
2.1 Literature Survey
Title: A Comparative Investigation and Evaluation of Oracle and Sql Server with respect
to Performance and Scalability.
Performance and Scalability are important factors determining database availability and reliability.
This is true especially now that computer systems ,due to the advent inclusion of the internet in
Online transaction processing (OLTP) and e-commerce applications , are becoming larger than
ever before to accommodate large user populations concurrently accessing the database. This
evolution gave birth to endearing need for high throughput, response time, good data consistency
and concurrency as will be seen from this research evaluation of Oracle 9i and SQL server 2000
DBMS. Anticipated deliverables of this research will include a set of comparative graphs from
performance tests and the accompanying technical explanation to support the results.
This research specifically explores and evaluates performance and scalability capabilities of SQL
server 2000 and Oracle 9i .This would be accomplished through the use of a combination of
standard benchmarks (TPC-C) embedded under third party software like Quest Central 2005 for
Oracle and SQL server and performance tuning tools like System Monitor and Analysis Manager
included with these products. Furthermore, technical features influencing performance and
scalability will be examined to support the benchmark results.
There are a lot of implementations of Ethereum Smart Contracts. We need to study and understand
many use cases and think innovatively to know how we can fit the smart contract technology in
currently existing system. Let us consider the example of Real Estate.
The following image explains on how the current system of buying/selling land or simply transfer
of property is done.
7
Consider a buyer named Alice, and seller Bob. The buyer Alice wants to buy a new house and she
approaches to Brokers to buy some property around her. The broker reaches seller Bob and shows
his property to his client Alice. Once Alice and Bob agree to transfer of the property, then lawyers
and insurance guys work out and finish the government process for transfer of this property and
money is exchanged with the property.
2.2 Disadvantages
• Inaccuracy
• Ambiguity
• Unclear Communication
• Takes time
• Less secured
• Inefficient
• Untrustworthy
8
CHAPTER 3
PROPOSED SYSTEM
The following image explains how transfer of property occurs when we use smart
contracts.
In smart contracts, we define the law for the process of buying and selling the land. Here Alice
buys land directly from Bob. The smart contract is executed in all the computers in the network.
When Bob sells land and a transaction is done, some computers in the network verify the
transaction and transfer of ownership is done. This process usually takes around 15seconds in
an Ethereum network.
This is how fast smart contracts are and also it overcomes all the disadvantages of the existing
systems.
9
CHAPTER 4
COMPARISION
The self-executing nature of these contracts makes them better suited to some industries over
others. Industries like banking, insurance, healthcare, and real estate stand to benefit from adopting
this technology. These industries are built upon a system of clear rules, algorithms, and
quantifiable terms of engagement. Automated contracts are less suitable for industries where
service levels are qualitative in nature, such as hospitality, food, and beverages.
Byzantine fault-tolerant algorithms allowed digital security through decentralization to form smart
contracts. Additionally, the programming languages with various degrees of Turing-completeness
as a built-in feature of some blockchains make the creation of custom sophisticated logic possible.
Notable examples of implementation of smart contracts are: Bitcoin also provides a Turing-
incomplete Script language that allows the creation of custom smart contracts on top of Bitcoin
like multisignature accounts, payment channels, escrows, time locks, atomic cross-chain trading,
oracles, or multi-party lottery with no operator.
Ethereum implements a nearly Turing-complete language on its blockchain, a prominent smart
contract framework. Ripple (Codius), smart contract development halted in 2015
Suppose you rent an apartment from me. You can do this through the blockchain by paying in
cryptocurrency. You get a receipt which is held in our virtual contract; I give you the digital entry
key which comes to you by a specified date. If the key doesn’t come on time, the blockchain
releases a refund. If I send the key before the rental date, the function holds it releasing both the
fee and key to you and me respectively when the date arrives. The system works on the If-Then
premise and is witnessed by hundreds of people, so you can expect a faultless delivery. If I give
you the key, I’m sure to be paid. If you send a certain amount in bitcoins, you receive the key. The
document is automatically canceled after the time, and the code cannot be interfered by either of
us without the other knowing since all participants are simultaneously alerted. You can use smart
contracts for all sort of situations that range from financial derivatives to insurance premiums,
breach contracts, property law, credit enforcement, financial services, legal processes and
crowdfunding agreements.
Government
Insiders vouch that it is extremely hard for our voting system to be rigged, but nonetheless, smart
contracts would allay all concerns by providing an infinitely more secure system. Ledger-protected
votes would need to be decoded and require excessive computing power to access. No one has that
much computing power, so it would need God to hack the system! Secondly, smart contracts could
hike low voter turnout. Much of the inertia comes from a fumbling system that includes lining up,
showing your identity, and completing forms. With smart contracts, volunteers can transfer voting
online and millennials will turn out en masse to vote for their Potus.
Management
10
The blockchain not only provides a single ledger as a source of trust, but also shaves possible
snarls in communication and workflow because of its accuracy, transparency, and automated
system. Ordinarily, business operations have to endure a back-and-forth, while waiting for
approvals and for internal or external issues to sort themselves out. A blockchain ledger
streamlines this. It also cuts out discrepancies that typically occur with independent processing
and that may lead to costly lawsuits and settlement delays.
Case history
In 2015, the Depository Trust & Clearing Corp. (DTCC) used a blockchain ledger to process more
than $1.5 quadrillion worth of securities, representing 345 million transactions.
11
CHAPTER 5
APPLICATIONS
When it comes to smart contracts, the number of use cases in industry and everyday life is
almost endless. Let us tell you about the most interesting applications and show you how the
implementation of smart contracts in business is already changing the world we live in.
5.1 Digital Identity
Today, different institutions hold different details about your life – bank records, ownership
rights, job details, demographic facts, etc. To collect all this information in one file, you would
need to carry a huge pile of papers, references, copies. It’s pretty inconvenient, especially, if you
have to pass an identity verification. Smart contracts solve this problem and allow to keep all the
data on one person in one place. Whenever something happens to you, it would be registered on
the blockchain to keep your identity holistic. Owing to this, KYC verification would become
instant. And your privacy wouldn’t be affected as you are the one to decide which information to
disclose.
5.2 Banking
Don’t you feel annoyed when you’re trying to make a money transfer, and you need to
cover a fee, pay a percentage of the sum you send, and then wait for a few days while the
transaction is being processed? Even though the modern banking system works rather smoothly,
its imperfections are hard to deny. Smart contracts do not require any intermediaries. Hence, you
pay no fees. As there’s no bureaucracy involved, transactions become fast and cheap. Moreover,
the transparency guaranteed by the blockchain reduces the possible risks of fraud.
5.4 Insurance
May you get into a minor car accident, the first thing you would worry about is an insurance
payment. If the accident is not your fault, you expect the guilty side to cover repair expenses. But
12
what would you do if this person denies their fault? Your chances of getting a refund are not too
inspiring. May the car be equipped with an IoT device reporting its location, speed, time of the
accident, you would have no reasons to worry. In case you’re right, the data on the blockchain
would prove your words, and you would get your payment automatically.
13
you get your reward, whenever you lose you can’t fool the system and keep your money. Gambling
becomes transparent and honest. The same algorithm applies to any paid computer game and e-
sports.
14
CHAPTER 6
FUTURE SCOPE
15
we’ll see below, my classification of decentralized autonomous organizations touches on such
concepts, and it is not quite clear exactly where they sit.
6.3 Decentralized Organizations
In general, a human organization can be defined as combination of two things: a set of
property, and a protocol for a set of individuals, which may or may not be divided into certain
classes with different conditions for entering or leaving the set, to interact with each other including
rules for under what circumstances the individuals may use certain parts of the property. For
example, consider a simple corporation running a chain of stores. The corporation has three classes
of members: investors, employees and customers. The membership rule for investors is that of a
fixed-size (or optionally quorum-adjustable size) slice of virtual property; you buy some virtual
property to get in, and you become an investor until you sell your shares. Employees need to be
hired by either investors or other employees specifically authorized by investors (or other
employees authorized by other employees authorized by investors, and so on recursively) to
participate, and can also be fired in the same way, and customers are an open-membership system
where anyone can freely interact with the store in the obvious officially sanctioned way for any
time. Suppliers, in this model, are equivalent to employees. A nonprofit charity has a somewhat
different structure, involving donors and members (charity recipients may or may not be
considered members; the alternative view sees the positive increments in the recipients’ welfare
as being the charity’s “product”).
The idea of a decentralized organization takes the same concept of an organization, and
decentralizes it. Instead of a hierarchical structure managed by a set of humans interacting in
person and controlling property via the legal system, a decentralized organization involves a set of
humans interacting with each other according to a protocol specified in code, and enforced on the
blockchain. A DO may or may not make use of the legal system for some protection of its physical
property, but even there such usage is secondary. For example, one can take the shareholder-owned
corporation above, and transplant it entirely on the blockchain; a long-running blockchain-based
contract maintains a record of each individual’s holdings of their shares, and on-blockchain voting
would allow the shareholders to select the positions of the board of directors and the employees.
Smart property systems can also be integrated into the blockchain directly, potentially allowing
DOs to control vehicles, safety deposit boxes and buildings.
16
DAO has internal capital; that is, a DAO contains some kind of internal property that is valuable
in some way, and it has the ability to use that property as a mechanism for rewarding certain
activities. BitTorrent has no internal property, and Bitcloud/Maidsafe-like systems have reputation
but that reputation is not a saleable asset. Bitcoin and Namecoin, on the other hand, do. However,
plain old DOs also have internal capital, as do autonomous agents.
Second, we can look at DOs. The obvious difference between a DO and a DAO, and the one
inherent in the language, is the word “autonomous”; that is, in a DO the humans are the ones
making the decisions, and a DAO is something that, in some fashion, makes decisions for itself.
This is a surprisingly tricky distinction to define because, as dictatorships are always keen to point
out, there is really no difference between a certain set of actors making decisions directly and that
set of actors controlling all of the information through which decisions are made. In Bitcoin, a 51%
attack between a small number of mining pools can make the blockchain reverse transactions, and
in a hypothetical decentralized autonomous corporation the providers of the data inputs can all
collude to make the DAC think that sending all of its money
to1FxkfJQLJTXpW6QmxGT6oF43ZH959ns8Cq constitutes paying for a million nodes’ worth of
computing power for ten years. However, there is obviously a meaningful distinction between the
two, and so we do need to define it.
My own effort at defining the difference is as follows. DOs and DAOs are both vulnerable to
collusion attacks, where (in the best case) a majority or (in worse cases) a significant percentage
of a certain type of members collude to specifically direct the D*O’s activity. However, the
difference is this: in a DAO collusion attacks are treated as a bug, whereas in a DO they are a
feature. In a democracy, for example, the whole point is that a plurality of members choose what
they like best and that solution gets executed; in Bitcoin’s on the other hand, the “default” behavior
that happens when everyone acts according to individual interest without any desire for a specific
outcome is the intent, and a 51% attack to favor a specific blockchain is an aberration. This appeal
to social consensus is similar to the definition of a government: if a local gang starts charging a
property tax to all shopowners, it may even get away with it in certain parts of the world, but no
significant portion of the population will treat it as legitimate, whereas if a government starts doing
the same the public response will be tilted in the other direction. Bitcoin is an interesting case here.
In general, it seems to be much closer to a DAO than a DO. However, there was one incident in
2013 where the reality proved to be rather different. What happened was that an exceptional block
was (at least we hope) accidentally produced, which was treated as valid according to the BitcoinQt
0.8 clients, but invalid according to the rules of BitcoinQt 0.7. The blockchain forked, with some
nodes following the blockchain after this exceptional block (we’ll call this chain B1), and the other
nodes that saw that block as invalid working on a separate blockchain (which we’ll call B2). Most
mining pools had upgraded to BitcoinQt 0.8, so they followed B1, but most users were still on 0.7
and so followed B2. The mining pool operators came together on IRC chat, and agreed to switch
their pools to mining on B2, since that outcome would be simpler for users because it would not
require them to upgrade, and after six hours the B2 chain overtook B1 as a result of this deliberate
action, and B1 fell away. Thus, in this case, there was a deliberate 51% attack which was seen by
the community as legitimate, making Bitcoin a DO rather than a DAO. In most cases, however,
17
this does not happen, so the best way to classify Bitcoin would be as a DAO with an imperfection
in its implementation of autonomy.
However, others are not content to classify Bitcoin as a DAO, because it is not really smart enough.
Bitcoin does not think, it does not go out and “hire” people with the exception of the mining
protocol, and it follows simple rules the upgrading process for which is more DO-like than DAO-
like. People with this view would see a DAO as something that has a large degree of autonomous
intelligence of its own. However, the issue with this view is that there must be a distinction made
between a DAO and an AA/AI. The distinction here is arguably this: an AI is completely
autonomous, whereas a DAO still requires heavy involvement from humans specifically
interacting according to a protocol defined by the DAO in order to operate. We can classify DAOs,
DOs (and plain old Os), AIs and a fourth category, plain old robots, according to a good old
quadrant chart, with another quadrant chart to classify entities that do not have internal capital thus
altogether making a cube:
18
CHAPTER 7
CONCLUSION
The potential of smart contracts cannot be limited. They can be used for small regular
agreements as well as contracts for governments and enterprises too. They allow traders and buyers
to track their purchase back in the supply chain which increases trust.
While third-parties like lawyers, government bodies etc. make a hole in our pockets in the form of
fees for making agreements; smart contracts save this money by eliminating the need for such
intermediaries. When it comes to using smart contracts, all we need to do is check the code before
the execution, everything after that will be done in an electronic way. Smart contracts provide us
with an opportunity to make our routine transactions and processes more streamlined and
automated.
The base of smart contracts are interfaces, business rules, and data. With evolving technology,
smart contracts will also need to be updated for eliminating any compatibility issues with operating
systems and perform their directed functions correctly. While smart contracts are still in their
developing phase, they might face certain vulnerability attacks. In order to make smart contracts a
part of our day to day life, both, cybersecurity practices as well as the platforms to create smart
contracts need to be updated from time to time.
19
CHAPTER 8
REFERENCES
[2] DAOs DACSs Das and more: An Incomplete Terminology Guide by Vitalik:
https://blog.ethereum.org/2014/05/06/daos-dacs-das-and-more-an-incomplete-terminology-
guide/
[7] Everything You Need to Know About Smart Contracts: A Beginner’s Guide:
https://hackernoon.com/everything-you-need-to-know-about-smart-contracts-a-beginners-guide-
c13cc138378a
20