Simple Ethereum Voting dapp using Truffle framework
The below blog posts explain each chapter in detail:
Simple Ethereum Voting dapp using Truffle framework
Home Page: https://www.zastrin.com
Simple Ethereum Voting dapp using Truffle framework
The below blog posts explain each chapter in detail:
I run the following command:
function transferTo(address account) {
if (!account.call.value(this.balance)()) throw;
}
This function appears on line 125 in Voting.sol
in chapter 3. I'm wondering why the function isn't simply: account.transfer(this.balance);
?
Promise failed to return
deployedContract.deploy({
... data: bytecode,
... arguments: [listOfCandidates.map(name => web3.utils.asciiToHex(name))]
... }).send({
... from: 'ENTER 1 OF 10 ACCOUNT ADDRESSES like 0xfb3....',
... gas: 1500000,
... gasPrice: web3.utils.toWei('0.00003', 'ether')
... }).then((newContractInstance) => {
... deployedContract.options.address = newContractInstance.options.address
... console.log(newContractInstance.options.address)
... });
**
Uncaught:
Error: Provided address "ENTER 1 OF 10 ACCOUNT ADDRESSES like 0xfb3...." is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted.
at Object.inputAddressFormatter (F:\ethereum_voting_dapp-master\ethereum_voting_dapp-master\chapter1\node_modules\web3-core-helpers\lib\formatters.js:398:11)
at Contract.getOrSetDefaultOptions [as _getOrSetDefaultOptions] (F:\ethereum_voting_dapp-master\ethereum_voting_dapp-master\chapter1\node_modules\web3-eth-contract\lib\index.js:304:66)
at Object._processExecuteArguments (F:\ethereum_voting_dapp-master\ethereum_voting_dapp-master\chapter1\node_modules\web3-eth-contract\lib\index.js:700:42)
at Object._executeMethod (F:\ethereum_voting_dapp-master\ethereum_voting_dapp-master\chapter1\node_modules\web3-eth-contract\lib\index.js:720:68)**
any idea on how to deploy a contract with a constructor bytes32 array?
html file links to app.js with incorrect path. Does it have an incorrect path? Or maybe does it use third library which allows to access to this file without of specifying the path to it like Meteor?
Transactions on blockchain can be removed due to chain reorganization.
When the vote transaction is executed in a block, the DApp update the vote count in the UI.
However, if the chain reorganization happens and the transaction got removed from history, but the vote count is not reverted.
One reproduce example is given below.
The transaction removed by chain reorganization should reflected to the UI, and the vote count should also be reverted.
it seems like it keep returning zero
var buyObject = {
value: 25,
from: web3.eth.accounts[0]
};
contractInstance.buy.call(buyObject).then(function(result) {
console.log(">>>> " + result);
web3.eth.getBalance(contractInstance.address, function(error, result) {
console.log(result);
console.log(web3.fromWei(result.toString()));
});
}).catch(function(err) {
console.log("Error creating contract!" + err);
console.log(err.stack);
});
Account 0 : 99.99999999999662
Account 1 : 100
Account 2 : 99.99999999999846
Hello. I was trying to deploy the contract of the chapter3 and the console printed this error:
The contract code couldn't be stored, please check your gas amount.
I compared the file 2_deploy_contracts.js used in chapter3 with used in chapter2 and I noticed that was missing the gas value as shown below:
// the actual chapter3 2_deploy_contracts.js file
var Voting = artifacts.require("./Voting.sol");
module.exports = function(deployer) {
deployer.deploy(Voting, 1000, web3.toWei('0.1', 'ether'), ['Rama', 'Nick', 'Jose']);
};
//what I did
var Voting = artifacts.require("./Voting.sol");
module.exports = function(deployer) {
deployer.deploy(Voting, 1000, web3.toWei('0.1', 'ether'), ['Rama', 'Nick', 'Jose'],{gas: 6700000});
};
It worked fine when I did it.
I don't know if it is correct or if I did something wrong.
Thanks!
Getting the following output on complining the code with :-
compiledCode = solc.compile(code)
Output:-
'{"errors":[{"component":"general","formattedMessage":"* Line 1, Column 1\\n Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n Extra non-whitespace after JSON value.\\n","message":"* Line 1, Column 1\\n Syntax error: value, object or array expected.\\n* Line 1, Column 2\\n Extra non-whitespace after JSON value.\\n","severity":"error","type":"JSONError"}]}'
PS C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server> npm run webpack-dev-server
[email protected] webpack-dev-server C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server
node examples/run-example.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server\examples\run-example.js'
er.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] webpack-dev-server: node examples/run-example.js
npm ERR! Exit status 1
PS C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server> npm run webpack-dev-server
[email protected] webpack-dev-server C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server
node examples/run-example.js
internal/modules/cjs/loader.js:983
throw err;
^
Error: Cannot find module 'C:\Users\Acer\newelection\ethereum_voting_dapp-master\chapter2\node_modules\webpack-dev-server\examples\run-example.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:980:15)
at Function.Module._load (internal/modules/cjs/loader.js:862:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js:18:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] webpack-dev-server: node examples/run-example.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] webpack-dev-server script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Acer\AppData\Roaming\npm-cache_logs\2020-04-25T21_56_53_268Z-debug.log
i am not able to run npm run dev getting the above error
Hi, first of all thanks for the great tutorial.
I just came across one minor issue. throw
in Voting.sol
is deprecated.
Does it make sense to replace it with revert()
?
On running command truffle console or truffle migrate, the following error is thrown everytime even accounts exist.
/usr/local/lib/node_modules/truffle/lib/environment.js:66
config.networks[config.network].from = accounts[0];
^
TypeError: Cannot read property '0' of null
at /usr/local/lib/node_modules/truffle/lib/environment.js:66:56
at /usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/property.js:119:13
at /usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/requestmanager.js:89:9
at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:119:13)
at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/truffle/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
Getting this error on deplying the chapter 3 application using truffle 3 ..
Please help!!
pragma solidity ^0.4.6; //We have to specify what version of the compiler this code will use
Line 1 of Voting.sol should probably read:
pragma solidity ^0.4.10; //We have to specify what version of the compiler this code will use
Given the change to:
account.transfer(this.balance);
on line 126 the contract will no longer compile on solc version <0.4.10.
This gives the error:
Compiling ./contracts/Voting.sol...
/home/vagrant/ethereum_voting_dapp/chapter3/contracts/Voting.sol:126:5: Error: Member "transfer" not found or not visible after argument-dependent lookup in address
account.transfer(this.balance);
^--------------^
Compiliation failed. See above.
On previous solc versions.
I'd do a pull request but I'm having trouble installing the latest Truffle at the moment so can't verify the fix.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.