Skip to content

Instantly share code, notes, and snippets.

(() => {
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const interface = JSON.parse(YOUR_CONTRACT_INTERFACE);
const VotingContract = web3.eth.contract(interface);
const contractInstance = VotingContract.at(YOUR_CONTRACT_ADDRESS);
// Default account is used if you don't specify from in function call.
//web3.eth.defaultAccount = web3.eth.accounts[0];
web3.personal.unlockAccount(web3.eth.accounts[0], YOUR_NODE_PASSWORD, 0);
<html>
<head>
<title>Hello World DApp</title>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
</head>
<body class="container">
<h1>A Simple Hello World Voting Application</h1>
<div class="table-responsive">
<table class="table table-bordered">
<thead>
pragma solidity ^0.4.6; //We have to specify what version of compiler this code will use
contract Voting {
/* mapping is equivalent to an associate array or hash
The key of the mapping is candidate name stored as type bytes32 and value is
an unsigned integer which used to store the vote count
*/
mapping (bytes32 => uint8) public votesReceived;
/* Solidity doesn't let you create an array of strings yet. We will use an array of bytes32 instead to store