I followed the following tutorial: https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2
Now this tutorial is not using the recent version of web3 but I tried to solve this with the web3 documentation.
This is how far I got:
>byteCode = compiledCode.contracts[':Voting'].bytecode
>deployedContract = VotingContract.new(['Rama','Nick','Jose'],{data: byteCode, from: web3.eth.accounts[0], gas: 4700000})
>deployedContract.address
>contractInstance = VotingContract.at(deployedContract.address)
I successfully compiled the byteCode and deployed the contract in the following way:
> VotingContract.deploy({ data: byteCode, arguments: [[web3.utils.asciiToHex("name1"),web3.utils.asciiToHex("name2"),web3.utils.asciiToHex("name3")]] }).send({ from: acc1, gas: 4700000, gasPrice: '3000000' }).on('confirmation', function(confirmationNumber, receipt){console.log(confirmationNumber + ' ' + receipt) }).then(function(instance) {contractInstance = instance});
Now I should have a contract instance, shouldn't I? Or is this something else? The author goes on to do the following:
>contractInstance = VotingContract.at(deployedContract.address)
I did this instead:
var contract3 = new web3.eth.Contract(byteCode, contractInstance.options.address, {from: acc1, gasPrice:'3000000'});
Now if I try to call methods on this contract like:
contract3.methods.totalVotesFor(web3.utils.toHex('name1')).call(acc1).then(function(returned, err) {console.log(returned + ' ' + err)});
I receive the following response:
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
> Unhandled rejection Error: Returned error: Error: VM Exception while executing eth_call: invalid opcode
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:59368:17
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:69306:5
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:11335:9
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:7895:16
at replenish (C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:8415:25)
at iterateeCallback (C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:8405:17)
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:8380:16
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:11332:13
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:69302:9
at C:\Path\node_modules\ethereumjs-testrpc\build\cli.node.js:63982:7
at Object.ErrorResponse (C:\Path\node_modules\web3-core-helpers\src\errors.js:29:16)
at C:\Path\node_modules\web3-core-requestmanager\src\index.js:137:36
at XMLHttpRequest.request.onreadystatechange (C:\Path\node_modules\web3-providers-http\src\index.js:64:13)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Path\node_modules\xhr2\lib\xhr2.js:64:18)
at XMLHttpRequest._setReadyState (C:\Path\node_modules\xhr2\lib\xhr2.js:354:12)
What might I be doing wrong?
Thanks for your help!