I use testrpc, web3 1.0 and strength to create a simple Dapp, but I always get this error and I can not find what is wrong. Please, help.
My javascript file:
const Web3 = require('web3');
const fs = require('fs');
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const code = fs.readFileSync('Voting.sol').toString();
const solc = require('solc');
const compiledCode = solc.compile(code);
const abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface);
const VotingContract = new web3.eth.Contract(abiDefinition);
const byteCode = compiledCode.contracts[':Voting'].bytecode;
const deployedContract = VotingContract
.deploy({data: byteCode, arguments: [['a','b','c']]})
.send({
from: '0x386fd5fbe3804f24b35477f06aa78a178ce021bd',
gas: 4700000,
gasPrice: '2000000000'
}, function(error, transactionHash) {})
.on('error', function(error){})
.on('transactionHash', function(transactionHash){})
.on('receipt', function(receipt){
console.log(receipt.contractAddress);
})
.then(function(newContractInstance) {
newContractInstance.methods.getList().call({from: '0x386fd5fbe3804f24b35477f06aa78a178ce021bd'}).then(console.log);
});
My contract file:
pragma solidity ^0.4.11;
contract Voting {
mapping (bytes32 => uint8) public votesReceived;
bytes32[] public candidateList;
function Voting(bytes32[] candidateNames) {
candidateList = candidateNames;
}
function getList() returns (bytes32[]) {
return candidateList;
}
function totalVotesFor(bytes32 candidate) returns (uint8) {
require(validCandidate(candidate) == false);
return votesReceived[candidate];
}
function voteForCandidate(bytes32 candidate) {
require(validCandidate(candidate) == false);
votesReceived[candidate] += 1;
}
function validCandidate(bytes32 candidate) returns (bool) {
for(uint i = 0; i < candidateList.length; i++) {
if (candidateList[i] == candidate) {
return true;
}
}
return false;
}
}
In addition, I run testrpc using the following command:
testrpc --account = "0xce2ddf7d4509856c2b7256d002c004db6e34eeb19b37cee04f7b493d2b89306d, 20000000000000000000000000000000000"
Any help would be greatly appreciated.
source
share