Skip to content

Instantly share code, notes, and snippets.

@enriquefynn
Last active August 20, 2018 15:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enriquefynn/194ea8a71107c96d6714b2c031124762 to your computer and use it in GitHub Desktop.
Save enriquefynn/194ea8a71107c96d6714b2c031124762 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const solc = require('solc')
const Web3 = require('web3');
const web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));
const address = web3.eth.accounts[0];
const code = fs.readFileSync('Voting.sol').toString()
const compiledCode = solc.compile(code)
const abiDefinition = JSON.parse(compiledCode.contracts[':Voting'].interface)
const byteCode = compiledCode.contracts[':Voting'].bytecode
const VotingContract = web3.eth.contract(abiDefinition)
const deployedContract = VotingContract.new(['Rama','Nick','Jose'], {
data: byteCode,
from: web3.eth.accounts[0], gas: 4712388
}, (err, contract) => {
if (contract.totalVotesFor !== undefined)
contract.totalVotesFor.call('Rama', console.log)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment