100% found this document useful (1 vote)
268 views23 pages

BlockChain Report 2

This document discusses an Ethereum decentralized voting application. It begins with an introduction to blockchain technology and how blockchains can be used to create decentralized applications. It then discusses the objectives of creating a smart contract for tracking assets in a supply chain. It provides examples of the basic structure of a smart contract written in Solidity and how data would be stored and transferred between wallets using mappings, events and functions.

Uploaded by

Mithun Reddy
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
100% found this document useful (1 vote)
268 views23 pages

BlockChain Report 2

This document discusses an Ethereum decentralized voting application. It begins with an introduction to blockchain technology and how blockchains can be used to create decentralized applications. It then discusses the objectives of creating a smart contract for tracking assets in a supply chain. It provides examples of the basic structure of a smart contract written in Solidity and how data would be stored and transferred between wallets using mappings, events and functions.

Uploaded by

Mithun Reddy
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/ 23

Ethereum decentralized voting application

CHAPTER 1

INTRODUCTION

1.1 INTRODUCTION TO BLOCKCHAIN

A blockchain, originally block chain, is a growing list of records, called blocks, which are linked using cryptography.
Each block contains a cryptographic hash of the previous block, a timestamp, and transaction data (generally
represented as a Merkle tree).

By design, a blockchain is resistant to modification of the data. It is "an open, distributed ledger that can record
transactions between two parties efficiently and in a verifiable and permanent way". For use as a distributed ledger, a
blockchain is typically managed by a peer-to-peer network collectively adhering to a protocol for inter-node
communication and validating new blocks. Once recorded, the data in any given block cannot be altered retroactively
without alteration of all subsequent blocks, which requires consensus of the network majority. Although blockchain
records are not unalterable, blockchains may be considered secure by design and exemplify a distributed computing
system with high Byzantine fault tolerance. Decentralized consensus has therefore been claimed with a blockchain.

Blockchain was invented by a person (or group of people) using the name Satoshi Nakamoto in 2008 to serve as the
public transaction ledger of the cryptocurrency bitcoin. The identity of Satoshi Nakamoto is unknown. The invention
of the blockchain for bitcoin made it the first digital currency to solve the double-spending problem without the need
of a trusted authority or central server. The bitcoin design has inspired other applications, and blockchains which are
readable by the public are widely used by cryptocurrencies. Blockchain is considered a type of payment rail. Private
blockchains have been proposed for business use.

A blockchain is a decentralized, distributed and public digital ledger that is used to record transactions across many
computers so that any involved record cannot be altered retroactively, without the alteration of all subsequent
blocks. This allows the participants to verify and audit transactions independently and relatively inexpensively.

1.2 OBJECTIVES OF THE PROJECT WORK

In our simplified case we would like to track assets throughout the supply chain. In reality, the data structures for the
assets might be more complicated, but we will focus on a few aspects only: name, description and manufacturer. It
should be guaranteed that there is only a single instance of an asset at any time which leads to a uniqueness requirement
of the ID. We would like to keep track of origin and history of the asset. The key actions that should be supported are
the creation of new assets as well as transfers of assets. Furthermore, there should be a possibility to check whether a
person is actually in the possession of the asset ownership certificate or not.

Department of ISE, NHCE Page 1


Ethereum decentralized voting application

For the supply chain, imagine, for example, a Value Adding Services DAO that owns an engraving robot. The DAO
is programmed to optimize various parameters for: revenue, utilization, prestige, and operates the business around
the engraving robot.

Possible sub-tasks of the DAO that could be covered in the program are:

 offering the services on a website and process orders


 employing an operator who inserts the workpieces
 commissioning shipping services
 ordering repair services and replacement of worn parts in the robot
 hiring a recruiting service for new employee

Value adding services are increasingly becoming part of the supply chain, be it compiling kits from single products
(such as adding a USB cable to a printer) or product customization (such as an engraving your name on your new
iPad).

These services can be mapped onto Smart Contracts in the supply chain and immediately billed on delivery. The
concept of Decentralized Autonomous Organization (DAO) even goes one step further. A DAO is instantiated in the
Blockchain as a virtual, independently operating organization. A DAO is a program that has money and pursues goals
based on its design.
The combination of Smart Contracts, payment, and business logic enables a new type of entity in the supply chain.
The services described are still very complex and might be too difficult to implement, but parts of it are quite viable
– for example, billing the rental machine time and the binding of the profits to a particular purpose, e.g. for charity

1.3 PROJECT FEATURES

Structure of the smart contract

The basic structure of a smart contract written in Solidity

pragma solidity ^0.4.2;

Department of ISE, NHCE Page 2


Ethereum decentralized voting application

import "assets.sol";

contract AssetTracker {
string id;

function setId(string serial) public {


id = serial;
}

function getId() public constant returns (string) {


return id;
}
}

The contract file opens with a section on the applicable Solidity language version. Pragmas are known from
compilers such as gcc. They give the compiler additional information on how to process the given code. This given
pragma tells the compiler to use the ‘^’ highest available language version above ‘0.4.2’.

Furthermore, you are able to import code from other files at the global scope level by using the well-known ‘import’
statement, just as in most other languages.
In this example we have added some public getter and setter functions that can be used both as an internal and as an
external function. Beyond this, there is the possibility to create events along the way that can be used to log
processes or states. We will make use of the events in order to keep track of supply chain events such as goods
receipt or asset creation.

A brief excursion to types and costs

The static types that are available, such as string, int, bool …, will come with the typical unary and binary operators.
You can find a full list of types here. You shouldn’t be lazy about learning and using the types properly, because this
will have impact on the running cost oft your transactions. The transaction effort, described in the unit gas, will
depend on the operations executed and the data stored. This effort is priced by you. If you pay more for the
execution of your code, your transaction will be preferred by the network, hence executed sooner.

Department of ISE, NHCE Page 3


Ethereum decentralized voting application

If you want to drill down into the economics of transactions, you should have a look at ‘Calculating Cost in
Ethereum Contracts‘ and ‘Ethgasstation‘ to get a feeling about the associated costs with your smart contract. The
details of gas cost for opcodes, e.g. the formerly used SSTORE opcode, can be found in the Ethereum yellow paper.
Another way to have a look at the cost is to use the online Solidity compiler that allows you to have a look at the
Ethereum Virtual machine code generated from your contract. It estimates the gas price and reveals the inner
workings of how the different data types are handled on the stack.

Tracking data structure

The following struct describes our simplified asset.

struct Asset {
string name;
string description;
string manufacturer;
bool initialized;
}

We use members such as describing properties such as name, description and process control variables such as
initialized and manufacturer. They are used to check whether this asset was already manufactured and who the
manufacturer is.

In order to store the assets, we create two mappings that will allow us to store asset properties as well as the relation
between assets and wallets based on asset uuids.

mapping(string => Asset) private assetStore;

is used later on to store assets under their respective uuid:

assetStore[uuid] = Asset(name, description, true, manufacturer);

For the wallet store, we use the following mapping:

Department of ISE, NHCE Page 4


Ethereum decentralized voting application

mapping(address => mapping(string => bool)) private walletStore;

is used later on to make the assignment of an asset to a wallet

walletStore[msg.sender][uuid] = true;

Declaring the events

For different real-world events in the supply chain, such as asset creation or asset transfer, we define counterparts
in the smart contract.

event AssetCreate(address account, string uuid, string manufacturer);


event RejectCreate(address account, string uuid, string message);
event AssetTransfer(address from, address to, string uuid);
event RejectTransfer(address from, address to, string uuid, string message);

Declaring the functions

The first function that we would need is the create asset function. It takes all information needed to specify the asset
and checks if the asset already exists. In this case we trigger a formerly declared event – RejectCreate(). If we have a
new asset at hand, we store the data in the asset store and create the relation between the message sender’s wallet
and the asset uuid.

function createAsset(string name, string description, string uuid, string manufacturer) {

if(assetStore[uuid].initialized) {
RejectCreate(msg.sender, uuid, "Asset with this UUID already exists.");
return;
}

assetStore[uuid] = Asset(name, description, true, manufacturer);


walletStore[msg.sender][uuid] = true;
AssetCreate(msg.sender, uuid, manufacturer);
}

Department of ISE, NHCE Page 5


Ethereum decentralized voting application

In order to transfer the asset, we create a function that takes the address of the target wallet along with the asset id.
We check two pre-conditions: The asset is actually existing and the transaction initiator is actually in possession of
the asset.

function transferAsset(address to, string uuid) {

if(!assetStore[uuid].initialized) {
RejectTransfer(msg.sender, to, uuid, "No asset with this UUID exists");
return;
}

if(!walletStore[msg.sender][uuid]) {
RejectTransfer(msg.sender, to, uuid, "Sender does not own this asset.");
return;
}

walletStore[msg.sender][uuid] = false;
walletStore[to][uuid] = true;
AssetTransfer(msg.sender, to, uuid);
}

We would also like to have access to the asset properties by just giving the uuid. Since it is currently not possible to
return structs in Solidity, we return a list of strings.

function getAssetByUUID(string uuid) constant returns (string, string, string) {

return (assetStore[uuid].name, assetStore[uuid].description, assetStore[uuid].manufacturer);

Department of ISE, NHCE Page 6


Ethereum decentralized voting application

Furthermore, we would like to have a simple way to prove the ownership of an asset without the need to fiddle
around the transaction log. So we create a helper function isOwnerOf().

function isOwnerOf(address owner, string uuid) constant returns (bool) {

if(walletStore[owner][uuid]) {
return true;
}

return false;
}

Once the contract is deployed, we can interface with the smart contract by using web3.js. The following example is
an excerpt for creating a new asset.

export const createAssetInContract = async (assetData, publicKey) =>; {


console.log('Creating asset...');
const atContract = await AssetTracker.deployed();
const asset = atContract.createAsset(
assetData.name,
assetData.description,
assetData.assetId,
assetData.manufacturer,
{ from: publicKey },
);

return asset;
};

This simple example shows a basic asset tracking functionality in the blockchain. There are many ways to improve
the design and the functionality, such as on-chain uuid generation.

Department of ISE, NHCE Page 7


Ethereum decentralized voting application

CHAPTER 2

SYSTEM DESIGN

System Design acts as a technical solution to satisfy the functional requirements of the system. This is the
important part of the project lifecycle in which functional specification requirements produced during system
requirement analysis is transformed into a physical architecture. The goal of this document is to create a blue print for
the development of the project. Focus is on deciding which modules are needed for the system, the overall specification
of modules and interpretation of these modules. System design is a modeling process. Here components are distributed
across the physical architecture, usable interfaces are designed, prototyped and technical specifications are created for
the Application Developers, enabling them to build and test the system.
System design is a semantic approach to create a new system. Design is a creative process. A good design
is the key to an effective system. The System design is defined as “The process of applying various techniques and
principles for the purpose of defining a process or a system in sufficient details to permit its physical realization.
System design phase acts as a bridge between the required specification and implementation phase.

2.1 Importance Of Blockchain And Smart Contracts

Along with the blockchain technology, smart contracts are of intense interest to business. Despite of its early
development they have been mostly existed in theory. Smart contract helps to solve the issue of mistrust between
parties and business partners. Smart contracts have a number of benefits for a wide range of industries, reducing
unnecessary costs and time expenditure while enhancing transparency.

Ethereum is a gold standard in the world of smart contracts and has the biggest capitalisation among other platforms.
The majority of token sales happen on the Ethereum platform, using the ERC-20 token standard. The main language
Ethereum smart contracts are written in is called Solidity. The first of it’s kind to provide Turing complete code
running capability on a decentralised network, Ethereum changed the distributed network industry forever.

Department of ISE, NHCE Page 8


Ethereum decentralized voting application

2.2 Architecture of Smart Contract

1. Go to http://remix.ethereum.org to launch your remix IDE.

2. The Remix IDE creates a sample voting contract for you called Ballot.sol. But we want to create a simple contract
of our own from scratch. Click on the + (plus) button at the top left corner to create a new file.

Fig 2.1 : Creation of new solidity file

Department of ISE, NHCE Page 9


Ethereum decentralized voting application

3. Give the file a name similar to Sample.sol. Type your code in this file.

2.3 Features of Smart Contract Used In The Project

1. Digital Ownership Certificates

2. Asset & Assembly Tracking

3. Proof of Origin

4. Trusted Maintenance Tracking

5. Integrated Financial Transaction

6. Distributed Product Master Data

7. Trusted Devices

8. Production Integration

9. Asset Management Platform

10. In-the-field Interface

2.4 FEATURES OF A SMART CONTRACT USED IN PROJECT

1. To deploy our smart contract to the Ethereum blockchain, we need to deploy through MetaMask via the injected
web3 and in our case running on the Ropsten Test Network.

2. Let’s compile our smart contract. Click on the compile tab at the top right corner and then click on the button start
to compile to compile the smart contract.
Hopefully it should compile without any error.

Department of ISE, NHCE Page 10


Ethereum decentralized voting application

Fig 2.2 : Compiling a solidity program

3. Next click on the Run tab to deploy the smart contract to the Ethereum blockchain.

Fig 2.3 : Running a solidity program

4. Click on the Deploy button to deploy the contract to the blockchain.


This action would invoke MetaMask via the Injected Web3.

Department of ISE, NHCE Page 11


Ethereum decentralized voting application

Fig 2.4 : Deploying a solidity program

5. You can increase the Gas Price to maybe 3 or 4 GWEI for faster transaction mining.
Finally click on the submit button to add the contract to the blockchain.

Fig 2.5 : Adding contract to the blockchain

6. After that click on the “Sent” tab on MetaMask to view your contract status.

Department of ISE, NHCE Page 12


Ethereum decentralized voting application

Fig 2.6 : View your contract status

7. Then click on the newly created contract to view you contract information on Etherscan.

Fig 2.7 : Transactions on Etherscan

We have now successfully created and deployed a smart contract into the Ethereum blockchain.

Department of ISE, NHCE Page 13


Ethereum decentralized voting application

CHAPTER 3

REQUIREMENTS AND SPECIFICATIONS

RESULTS AND DISCUSSIONS

In summary, the concept does work successfully, but there are still uncertainties. In the meantime we have been
working on enhancing usability and on covering more and more aspects of the full supply chain platform. There are
known aspects to work on and adjustments to full production environments remain to be made.

HARDWARE REQUIREMENTS

1. Processor : Intel core processor


2. Speed : 2.50 GHz
3. RAM : Minimum of 256MB
4. Hard disk : 1 TB

SOFTWARE REQUIREMENTS

1. OS : Windows 7/8/10
2. Developing language : Solidity
3. Tools used : Remix IDE, MetaMask, Etherscan

TOOLS BEING USED

1) Remix IDE
Remix is an Ethereum IDE for the smart contract programming language called Solidity and it has an integrated
debugger and testing environment.
You can go to http://remix.ethereum.org to launch your Remix IDE.
Remix is a good solution if you intend to :
a. Develop smart contracts (remix integrates a solidity editor).
b. Debug a smart contract’s execution.
c. Access the state and properties of already deployed smart contract.
d. Debug already committed transaction.

Department of ISE, NHCE Page 14


Ethereum decentralized voting application

e. Analyse solidity code to reduce coding mistakes and to enforce best practices.
f. Together with Mist or MetaMask (or any tool which injects web3), Remix can be used to test and debug a dApp.
2) MetaMask
MetaMask is a bridge that allows you to visit the distributed web of tomorrow in your browser today. It allows you
to run Ethereum dApps right in your browser without running a full Ethereum node. MetaMask includes a secure
identity vault, providing a user interface to manage your identities on different sites and sign blockchain transactions.
You can install the MetaMask add-on in Chrome, Firefox, Opera, and the new Brave browser.
You can use https://metamask.io/ to download MetaMask extension.
Follow the below steps to create an account. Make sure to save the 12 word passphrase because it’s the only way to
recover your account if you forget your password or private key.
You now have an account on MetaMask and you can use it for interacting with dApps and Smart Contracts. Make
sure you switch the account to Ropsten Test Network.
Click on the buy button > Ropsten Test Faucet and request for as many faucet ethers that you can get.

3) Etherscan
Etherscan is the leading BlockExplorer for the Ethereum Blockchain. A BlockExplorer is basically a search
engine that allows users to easily lookup, confirm and validate transactions that have taken place on the Ethereum
Blockchain.
We are independently operated and developed by a team of individuals who are truly passionate and excited about
the kinds of decentralized information and infrastructure applications that Ethereum makes possible.
You can view all your wallet transactions on https://etherscan.io/ Etherscan website.

Department of ISE, NHCE Page 15


Ethereum decentralized voting application

CHAPTER 4

IMPLEMENTATION

pragma solidity ^0.4.18;

contract Voting {

event AddedCandidate(uint candidateID);

struct Voter {

string uid; // bytes32 type are basically strings

uint candidateIDVote; }

struct Candidate {

string name;

string party;

bool doesExist; }

uint numCandidates; // declares a state variable - number Of Candidates

uint numVoters;

mapping (uint => Candidate) candidates;

mapping (uint => Voter) voters;

function addCandidate(string name, string party) public {

uint candidateID = numCandidates++;

candidates[candidateID] = Candidate(name,party,true);

AddedCandidate(candidateID); }

function vote(string uid, uint candidateID) public {

if (candidates[candidateID].doesExist == true) {

Department of ISE, NHCE Page 16


Ethereum decentralized voting application

uint voterID = numVoters++; //voterID is the return variable

voters[voterID] = Voter(uid,candidateID); } }

function totalVotes(uint candidateID) view public returns (uint) {

uint numOfVotes = 0; // we will return this

for (uint i = 0; i < numVoters; i++) {

if (voters[i].candidateIDVote == candidateID) {

numOfVotes++; } }

return numOfVotes;

function getNumOfCandidates() public view returns(uint) {

return numCandidates;

function getNumOfVoters() public view returns(uint) {

return numVoters;

function getCandidate(uint candidateID) public view returns (uint,string, string) {

return (candidateID,candidates[candidateID].name,candidates[candidateID].party);

Department of ISE, NHCE Page 17


Ethereum decentralized voting application

CHAPTER 5

SNAPSHOTS

Fig 5.1 : Compiled code on Remix IDE

Fig 5.2 : Account details for JavaScript VM

Department of ISE, NHCE Page 18


Ethereum decentralized voting application

Fig 5.3 : Deployed contract

Fig 5.4 : Input and output fields for functions

Department of ISE, NHCE Page 19


Ethereum decentralized voting application

Fig 5.5 : Add candidates

Fig 5.6 : Vote for candidate

Department of ISE, NHCE Page 20


Ethereum decentralized voting application

Fig 5.7 : Get candidates

Fig 5.8 : Number of candidates and voters

Fig 5.9 : Add candidates

Department of ISE, NHCE Page 21


Ethereum decentralized voting application

CHAPTER 6
CONCLUSION AND FUTURE SCOPE
Conclusion
Many functions of the blockchain can contribute to solving problems in the supply chain, and even new
business models are possible. The adoption of blockchain technology in the supply chain domain will not happen
overnight. But over time, we might see more and more applications in different areas and maybe some disruptive
change at one point or another.

The blockchain-enabled supply chain platform is far from being complete by now and a work in progress.
This is to develop ideas about the different use cases and parts of the platform.

In summary, the concept does work successfully, but there are still uncertainties. In the meantime we have been
working on enhancing usability and on covering more and more aspects of the full supply chain platform. There are
known aspects to work on and adjustments to full production environments remain to be made.

Future Scope

This method of voting can be used for directly voting from any place instead of actually going to the polling booths.
The main objective of the proposed system is to increase the voting percentage and even to improve the security of
voting system with valid votes.

This system will be very secure as the votes cannot be tampered because: Any outside or inside attacker must have
control of 51% of the nodes to alter the record. Even if the attacker is able to achieve that while incorrectly entering
user votes with their real IDs under the radar, end to end voting systems could allow voters to verify whether their vote
was correctly entered in the system, making the system extremely safe.

Department of ISE, NHCE Page 22


Ethereum decentralized voting application

REFRENCES

[1]. Blog.codecentric
[2]. Wikipedia.com
[3]. Medium.com
[4]. Programtheblockchain.com

Department of ISE, NHCE Page 23

You might also like