基于区块链的毕业设计E-Voting-Ethereum – 电子投票以太坊

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计E-Voting-Ethereum – 电子投票以太坊 是一篇很好的国外资料

E-Voting-Ethereum

A Blockchain based code for E Voting System which prevents miscounting of votes and stores the votes in different locations so that they cannot be tampered with.

Smart Contract

The election.sol placed in /ethereum/contracts is written in solidity v0.4.17 which contains the smart contract written for returning a list of voters, add a candidate, add a voter, cast a vote, return a candidate, return list of candidates, and much more. The manager can also add candidates or voters to the contract. The manager will be the one who deploys the smart contract. Only the manager can find the complete results of the eletion. We have calculated the number of voted for a particular candidate by iterating a chain. This number is then typecasted to uint. We also add a require statement in calculateVotes() which checks if the function is called by the manager or not. If not, then this function will not return anything. You can read more about smart contracts here. You can read more about the solidity language here.

Compiling the Smart Contract

To compile the smart contract we will be using solc compiler which is used to compile solidity codes. The compile code is placed in compile.js. The code is written in JavaScript.

Testing our Smart Contract

The election.test.js file, written in JavaScript tests our smart contracts by using multiple testcases written in it. We will be using mocha as the testing framework. Read more about mocha here.

Deploying our Smart Contract

The deploy.js file will deploy our smart contract to the Rinkeby Test Network. This network is similar to the main Ethereum Network but the only difference is that we don’t need to pay for deploying our smart contracts. It works completely on the concept of virtual money.

Steps to configure the project and to run our Smart Contract and deploy it on Rinkeby TestNet.

  1. Clone this source repository on your desired local path on machine.
  2. Install NodeJS in your computer from here. Use the recommended version.
  3. Install Git in your computer from here.
  4. Open up your cmd. Navigate to the folder Lottery in your cmd.
  5. Run the command- ‘npm init’ in our Lottery folder. This will create a package.json file in your directory.
  6. Install packages Truffle, Mocha, Ganache-CLI and Web3 by running the command ‘npm install –save truffle-hdwallet-provider@0.0.3 mocha ganache-cli web3’. Truffle is a development environment, testing framework and asset pipeline for Ethereum. Mocha is a testing framework which will be required by our lottery.test.js file. Ganache provides a environment for truffle. Web3 is a collection of libraries which allows you to interact with a local or remote ethereum node.
  7. To compile our smart contract, run command ‘node compile.js’.
  8. To test our smart contract, run ‘npm run test’.
  9. Install MetaMask which is an extension for browsers like Chrome to easily track your transactions and accounts.
  10. Finally, deploy our contract on the Rinkeby network by running command ‘node deploy.js’

电子投票以太坊eth

一种基于区块链blockchain的电子投票系统代码,用于防止错误计算选票,并将选票存储在不同的位置,以便它们不会被篡改。

智能合约

选举.sol放置在/ethereum/contracts中的是solidity v0.4.17,其中包含用于返回投票者列表、添加候选人、添加投票者、投一票、返回候选人、返回候选人列表等的智能合约。经理还可以将候选人或选民添加到合同中。经理将是部署智能合约的人。只有经理才能找到完整的选举结果。我们通过迭代一个链来计算投票给某个候选人的人数。然后将此数字键入uint。我们还在calculateVotes()中添加了一个require语句,用于检查函数是否由管理器调用。否则,此函数将不返回任何内容。您可以在这里阅读有关智能合约的更多信息。你可以在这里读到更多关于稳固语言的内容。

编译智能合约

要编译智能合约,我们将使用solc编译器,它用于编译稳定代码。编译代码放在编译.js. 代码是用JavaScript编写的。

测试智能合约

测试.js用JavaScript编写的文件通过使用多个用它编写的测试用例来测试我们的智能合约。我们将使用摩卡作为测试框架。阅读更多关于摩卡的信息。

部署智能合约

部署.js文件将把我们的智能合约部署到Rinkeby测试网络。这个网络类似于以太坊eth的主网络,但唯一的区别是我们不需要为部署智能合约付费。它完全基于虚拟货币的概念。

配置项目、运行智能合约并将其部署到Rinkeby TestNet的步骤。

  1. 在计算机上所需的本地路径上克隆此源存储库。
  2. 从这里在计算机中安装NodeJS。使用推荐的版本。
  3. 从这里将Git安装到您的计算机中。
  4. 打开你的命令。导航到cmd中的乐透文件夹。
  5. 在彩票文件夹中运行命令-“npm init”。这将创建一个包.json文件在您的目录中。
  6. 通过运行命令npm Install–save来安装Truffle、Mocha、Ganache CLI和Web3包松露钱包提供商@0.0.3mocha ganache cli web3’。Truffle是以太坊eth的开发环境、测试框架和资产管道。摩卡是一个测试框架,这将是我们的要求彩票测试.js文件。甘纳切为块菌提供了生长环境。Web3是一个库集合,允许您与本地或远程以太坊eth节点进行交互。
  7. 要编译智能合约,请运行命令’node’编译.js’.
  8. 要测试我们的智能合约,请运行“npm run test”。
  9. 安装MetaMask,它是Chrome等浏览器的一个扩展,可以方便地跟踪您的交易和帐户。
  10. 最后,通过运行command’节点,将我们的合同部署到Rinkeby网络上部署.js’

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/20553.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计E-Voting-Ethereum – 电子投票以太坊

提供最优质的资源集合

立即查看 了解详情