Coder Social home page Coder Social logo

election's Introduction

Election - DAPP Tutorial

Build your first decentralized application, or Dapp, on the Ethereum Network with this tutorial!

Full Free Video Tutorial:** https://youtu.be/3681ZYbDSSk

2019 Updated Code

https://github.com/dappuniversity/election/tree/2019_update

Follow the steps below to download, install, and run this project.

Dependencies

Install these prerequisites to follow along with the tutorial. See free video tutorial or a full explanation of each prerequisite.

Step 1. Clone the project

git clone https://github.com/dappuniversity/election

Step 2. Install dependencies

$ cd election
$ npm install

Step 3. Start Ganache

Open the Ganache GUI client that you downloaded and installed. This will start your local blockchain instance. See free video tutorial for full explanation.

Step 4. Compile & Deploy Election Smart Contract

$ truffle migrate --reset You must migrate the election smart contract each time your restart ganache.

Step 5. Configure Metamask

See free video tutorial for full explanation of these steps:

  • Unlock Metamask
  • Connect metamask to your local Etherum blockchain provided by Ganache.
  • Import an account provided by ganache.

Step 6. Run the Front End Application

$ npm run dev Visit this URL in your browser: http://localhost:3000

If you get stuck, please reference the free video tutorial.

election's People

Contributors

gwmccubbin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

election's Issues

Uncaught promise in "app.js" & no table visible on browser.

Hello, I have run the lite-server and connected metamask with the account in ganache and yet I am unable to see the table that should appear as per the Tutorial @1:11:14. I am also getting a promise error which I don't know how to resolve. Help will be highly appreciated.
Setup
Truffle = v.5.3.6
web3 = v.1.3.6
node = v.12.16.1
Screenshot 2021-05-15 at 11 45 48 PM
Screenshot 2021-05-15 at 11 46 24 PM

facing this Issue while running command "truffle test".

Using network 'development'.

Error: Cannot find module 'fs-extra'
Require stack:

  • /usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/debugger.js
  • /usr/lib/node_modules/truffle/build/cli.bundled.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:996:19)
    at require (node:internal/modules/cjs/helpers:92:18)
    at Object.call (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/external "fs-extra":1:18)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/compile-common/dist/src/profiler/updated.js:33:26)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/compile-common/dist/src/profiler/profiler.js:20:19)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/compile-common/dist/src/profiler/index.js:3:18)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/compile-common/dist/src/index.js:25:18)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/debugger/lib/session/index.js:31:1)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/debugger/lib/debugger.js:4:1)
    at r (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at Object.call (/Users/tyler/projects/truffle/packages/debugger/debugger.js:2:16)
    at webpack_require (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:19:22)
    at /usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/bootstrap:83:10
    at factory (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/debugger.js:1:1152)
    at /usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/universalModuleDefinition:3:20
    at Object. (/usr/lib/node_modules/truffle/node_modules/@truffle/debugger/dist/webpack/universalModuleDefinition:1:1)
    at Module._compile (node:internal/modules/cjs/loader:1092:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    Truffle v5.2.4 (core: 5.2.4)
    Node v15.11.0

i tried alot, i also installed fs-extra command separately but didn't worked. kindly help me.

my package.json is:

{
"name": "pet-shop",
"version": "1.0.0",
"description": "",
"main": "truffle.js",
"directories": {
"test": "test"
},
"scripts": {
"dev": "lite-server",
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^4.3.4",
"fs-extra": "^3.0.1",
"lite-server": "^2.3.0",
"mocha": "^8.3.2"
},
"dependencies": {
"fs": "^0.0.1-security"
}
}

issues with meta mask

Hi, I've had some issues getting metamask to work, I can never get past the loading screen, it is connected to ganache and I have updated the code in my app.js file as others have recommended, but the issue still persists

unable to migrate

throw new Error("Could not find artifacts for " + import_path + " from any sources");

Trying to convert the callback tests to async

The code above is what i wrote to convert the tests to be asynchronous, however, my test is not passing. The code below is from the lecture and it works, so the mistake could not be in my smart contract or test environment. Is anyone able to spot the issue from my async test?

image

app.candidate()

I got stuck on this

truffle(development)> app.candidate()
Thrown:
evalmachine.:0
app.candidate()
^

TypeError: app.candidate is not a function
at evalmachine.:0:5
at sigintHandlersWrap (vm.js:269:15)
at Script.runInContext (vm.js:124:14)
at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:222:1)
at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:237:1)
at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/repl.js:131:1)
at bound (domain.js:419:14)
at REPLServer.runBound [as eval] (domain.js:432:12)
at REPLServer.onLine (repl.js:716:10)
at REPLServer.emit (events.js:223:5)

terminal you are using

I have two issue one I can't use the subl . command on my node.js terminal and I also can't or any of the other command like touch contracts... it keeps saying that not recognized as an internal or external command. I am using Windows 7/10 and I see you are using mac.. Is there something in the steps that you are not sharing.. I have been doing this for two days since I have enrolled in you boot camp

issue in front-end

2021-01-28-17-44-37.mp4

when i import an account from ganache it seems normal but when i import another account , there are 2 extra rows appeared in front end
Screenshot 2021-01-30 173217
in the 3rd account there are more 2 rows of candidates appeared in front end...the more account i import every time 2 extra rows added in front end!!!
Screenshot 2021-01-30 173515
plz help!!!...how can i solve this???...i can not identify the problem!!!

Issue in truffle migrate

When I try to do truffle migrate --reset
The compilation is successful but once the migration for 1_initial_migration.js starts it gets killed.

Truffle Test ReferenceError: accounts not defined

I am following an Election.sol tutorial and when I tried to test the function below, I get ReferenceError : accounts not defined. I'm not sure how to fix this.

var Voting = artifacts.require("./Voting.sol");

contract("Voting", function(accounts){
var votingInstance;

//to check initialisation

it("initialises with two candidates", function() {
	return Voting.deployed().then(function(instance){
		return instance.candidatesCount();
	}).then(function(count){
		assert.equal(count, 2);
	});
});

});

it("it initialises the candidates with the correct values", function() {
	return Voting.deployed().then(function(instance) {
		votingInstance = instance;
		return votingInstance.candidates(1);

	}) .then(function(candidate) {
		assert.equal(candidate[0], 1, "contains the correct id");
		assert.equal(candidate[1], "Richard Denton", "contains the correct name");
		assert.equal(candidate[2], 0, "contains the correct vote count");
		return votingInstance.candidates(2);
	}).then(function(candidate){
		assert.equal(candidate[0], 2, "contains the correct id");
		assert.equal(candidate[1], "Jeff Bridges", "contains the correct name");
		assert.equal(candidate[2], 0, "contains the correct vote count");
	});

});
           it("allows a voter to cast a vote", function() {
          return Voting.deployed().then(function(instance) {
          votingInstance = instance;
          candidateId = 1;
        return votingInstance.vote.call(candidateId, { from: accounts[0] });
}).then(function(receipt) {
  assert.equal(receipt.logs.length, 1, "an event was triggered");
  assert.equal(receipt.logs[0].event, "votedEvent", "the event type is correct");
  assert.equal(receipt.logs[0].args._candidateId.toNumber(), candidateId, "the candidate id is correct");
  return votingInstance.voters(accounts[0]);
}).then(function(voted) {
  assert(voted, "the voter was marked as voted");
  return votingInstance.candidates(candidateId);
}).then(function(candidate) {
  var voteCount = candidate[2];
  assert.equal(voteCount, 1, "increments the candidate's vote count");
})

});

facing issue while connecting to MetaMask

when I enable MetaMask in crome and setup to required accounts, localhost web page is showing loading evin i had properly setup MetaMask as shown in image.

Capture333
But when I dissabled the MetaMask, It is showing proper output with account at index 0 as shown below:
Capture444
truffle version
Truffle v5.1.26 (core: 5.1.26)
Solidity - 0.4.25 (solc-js)
Node v12.13.0
Web3.js v1.2.1
Please help me getting out of this.

Question

I have a question if i have html page which i call it by "localhost/page-name.php" in the browser how can i call the page for voting which is called by using "localhost:3000" for example by clicking a link or it a useless method?? So how can connect them.
I create mysql database so the voter check his information then go to voting page which is called by "localhost:3000"

Delayed Render

Anyone else encounter a scenario where the candidates do not render the first time when the UI is displayed, but upon refreshing, the candidates finally appear?
image

I have Issue vote not get casted

i trying to cast vote but there are some errors when submit the vote.
126 castVote: function() {
127 var candidateId = $('#candidatesSelect').val();
128 App.contracts.Election.deployed().then(function(instance) {
129 return instance.vote(candidateId, { from: App.account });
130 }).then(function(result) {
131 // Wait for votes to update
132 $("#content").hide();
133 $("#loader").show();
134 }).catch(function(err) {
135 console.error(err);
136 });
137 }
138 };

at line no 135

Screenshot (56)

The command 'truffle migrate' fails conditionally

If the command 'truffle" is run in the cmder (or just plain windows cmd.exe) tool yields, then it would fail, if the current folder contains any Ethereum project

image

If you run the same command in a folder that does not contain an Ethereum project, then the expected behavior takes place:

Truffle v4.1.13 - a development framework for Ethereum

Usage: truffle <command> [options]

Commands:
  init      Initialize new and empty Ethereum project
  compile   Compile contract source files
  migrate   Run migrations to deploy contracts
  deploy    (alias for migrate)
  build     Execute build pipeline (if configuration present)
  test      Run JavaScript and Solidity tests
  debug     Interactively debug any transaction on the blockchain (experimental)
  opcode    Print the compiled opcodes for a given contract
  console   Run a console with contract abstractions and commands available
  develop   Open a console with a local development blockchain
  create    Helper to create new contracts, migrations and tests
  install   Install a package from the Ethereum Package Registry
  publish   Publish a package to the Ethereum Package Registry
  networks  Show addresses for deployed contracts on each network
  watch     Watch filesystem for changes and rebuild the project automatically
  serve     Serve the build directory on localhost and watch for changes
  exec      Execute a JS module within this Truffle environment
  unbox     Download a Truffle Box, a pre-built Truffle project
  version   Show version number and exit

See more at http://truffleframework.com/docs

for whatever reason, it doesn't throw exception. i fixed the test to check for failed tx status instead: https://github.com/pauluhn/election/blob/paul/test/election.js#L54

    for whatever reason, it doesn't throw exception. i fixed the test to check for failed tx status instead: https://github.com/pauluhn/election/blob/paul/test/election.js#L54

Originally posted by @pauluhn in #1 (comment)

I am still getting an error and my "double voting" test is failing

  1. Contract: Election
    vote fails for double voting:
    AssertionError: accepts first vote: expected <BN: 0> to equal 1

Unable to vote

capture

After selectting a candidate and clicking vote, nothing happens. I later on found some errors in the console.Any one experiencing this ?

Candidates not showing in my dropdown menu

I've been following the tutorial and everything has been going okay except for a couple of things:
I can't pass the last 3 truffle tests and the candidates don't show in the dropdown so I can't vote. Any ideas?

Contract: Election
โˆš initializes with two candidates (244ms)
โˆš it initializes the candidates with the correct values (359ms)

2 passing (957ms)
3 failing

  1. allows a voter to cast a vote:
    ReferenceError: accounts is not defined
    at C:\Users\Tammy\election\test\election.js:35:55
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

  2. vote fails for invalid candiates:
    ReferenceError: accounts is not defined
    at C:\Users\Tammy\election\test\election.js:53:46
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

  3. vote fails for double voting:
    ReferenceError: accounts is not defined
    at C:\Users\Tammy\election\test\election.js:71:48
    at processTicksAndRejections (node:internal/process/task_queues:94:5)

image

Multiple render

What is the solution for multiple rendering? When i add a new account and reload the page the list of candidates is showing multiple times. I have tried modifying listenForEvents in app.js, but nothing seems to work.
capture2

constructor issue

there's a change in solidity constructor. Change (contracts/Election.sol) from

    // Constructor
    function Election () public {
        candidate = "Candidate 1";
    }

to the following:

    // Constructor
    constructor() public {
        candidate = "Candidate 1";
    }

Unable To Vote: Accounts Undefined

I am unable to call app.vote(1, from: web3.eth.accounts[0]}), but not because I have insufficient Ether (premise of an issue raised by someone else)

My program, for some reason, treated all the accounts array values as undefined..

Attached below is a screenshot detailing how I have a list of addresses, but none of those are stored within web3.eth.accounts, and I am unsure why
image

Attempted to fix this issue by manually setting an address equal to a memory location within the accounts array in Git bash. However, it gives an error message of an unrecognized account when calling app.vote
image
image

In both instances, I have null accounts and accounts that are not recognized. I have been stuck for nearly 2 hours. Where is the problem localized? Within what file are these accounts instantiated to begin with? (assume no new files)

Votes are not increased

Hi!

First of all, thank you for this great tutorial. I'm having problems to get votes count increased:

captura de pantalla 2018-07-11 a las 18 39 42

The pop-up from Metamask appears and I click "submit" but nothing happens. The only vote that has been counted comes from and execution done with Safary Browser.

I have clone the complete project without changes and the only difference I see is the solidity version of the truffle compiler (0.4.24)

Thank you!

eth.web3.accounts

web3.eth.accounts is not working in the console and even in the js test.
after long googling, I realize that I can now use eth.web3.getAccounts()..
But the problem since this is a method, I can't pass index to getAccounts to get the first account(account 0).

So basically my problem is how can I get a single account from getAccounts function..
anyone have an idea?

truffle migrate

Hi I am working on election Dapp after downloading the update. After running the truffle migrate --reset and I got the message.

Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify "pragma solidity 0.4.20".
Please update your truffle config or pragma statement(s).
(See https://truffleframework.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

Compilation failed. See above.
at Object.compile (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:80:1)
Truffle v5.1.11 (core: 5.1.11)
Node v12.14.1
Apparently the Truffle update is conflicting with the code. Any way to fix this? I tried changing the eversion on the election.sol file but was unable to move forward with the step after doing so.

Candidates are repeated after casting votes from different account

Dear Gregory,
Thank you for wonderful video lecture. I want to report two issues.

    1. I have casted votes from two different accounts. And casted votes for two different candidates : Keshav Rao (Candidate 1) and Chandrababu Naidu (Candidate 2). When I am trying to caste votes from the third account, I see that in the drop down menu, the candidates count have increased and it is repeating the same candidates twice.
    1. When I am trying to caste vote from different accounts, why the outcome of already casted votes (which means election is in process) are displaying? It should not be done.
      Election_Blockchain

Election_2

truffle compile error

I got a compile error when i compile election.sol, it show's like this

/home/js/election/contracts/Election.sol:24:5: Warning: This declaration shadows an existing declaration.
function Election () public {
^ (Relevant source part starts here and spans across multiple lines).
/home/js/election/contracts/Election.sol:3:1: The shadowed declaration is here:
contract Election {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Migrations.sol:11:3: Warning: This declaration shadows an existing declaration.
function Migrations() {
^ (Relevant source part starts here and spans across multiple lines).
/home/js/election/contracts/Migrations.sol:3:1: The shadowed declaration is here:
contract Migrations {
^ (Relevant source part starts here and spans across multiple lines).

/home/js/election/contracts/Election.sol:24:5: SyntaxError: Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
function Election () public {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Migrations.sol:11:3: SyntaxError: Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
function Migrations() {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Migrations.sol:11:3: SyntaxError: No visibility specified. Did you intend to add "public"?
function Migrations() {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Migrations.sol:15:3: SyntaxError: No visibility specified. Did you intend to add "public"?
function setCompleted(uint completed) restricted {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Migrations.sol:19:3: SyntaxError: No visibility specified. Did you intend to add "public"?
function upgrade(address new_address) restricted {
^ (Relevant source part starts here and spans across multiple lines).
,/home/js/election/contracts/Election.sol:29:28: TypeError: Data location must be "storage" or "memory" for parameter in function, but none was given.
function addCandidate (string _name) private {
^----------^

AssertionError on double voting and invalid candidates tests

2 failing

  1. Contract: Election throws an exception for invalid candiates:
    AssertionError: error message must contain revert
    at test/Election.js:63:13
    at
    at process._tickCallback (internal/process/next_tick.js:188:7)

  2. Contract: Election throws an exception for double voting:
    AssertionError: error message must contain revert
    at test/Election.js:87:13
    at
    at process._tickCallback (internal/process/next_tick.js:188:7)

Possibly a problem with the require function?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.