Skip to content

Instantly share code, notes, and snippets.

@maheshmurthy
maheshmurthy / Voting.sol
Last active January 22, 2023 13:23
Simple solidity contract to vote for a candidate and see the results
View Voting.sol
pragma solidity ^0.6.4;
// We have to specify what version of compiler this code will compile with
contract Voting {
/* mapping field below is equivalent to an associative array or hash.
The key of the mapping is candidate name stored as type bytes32 and value is
an unsigned integer to store the vote count
*/
mapping (bytes32 => uint256) public votesReceived;
@maheshmurthy
maheshmurthy / delegators-griff.eth.txt
Last active November 22, 2022 04:01
ENS Delegators - griff.eth
View delegators-griff.eth.txt
Subgraph Page: https://thegraph.com/hosted-service/subgraph/show-karma/dao-delegates
Query:
{
delegatorOrganizations(
first: 1000,
//skip:1000,
where:{
organization: "ens",
delegate: "0x839395e20bbb182fa440d08f850e6c7a8f6f0780"
}
@maheshmurthy
maheshmurthy / index.html
Last active September 20, 2022 21:22
index.html with ethers.js
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World DApp</title>
<link href='https://fonts.googleapis.com/css?family=Open Sans:400,700' rel='stylesheet' type='text/css'>
<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">
View attestation.txt
I contributed to the Semaphore Trusted Setup Multi-Party Ceremony.
The following are my contribution signatures:
Circuit: semaphore24
Contributor # 349
Hash: 7cb5305a c34dd2ba 2d3cb87d 54884cf8
3ba41a60 0882bdcc 9d583dc0 136309bc
f8d77e6f b1ee5803 2f2d5b8d 3620ad52
faffb3f3 aec21610 ff856214 1b847189
@maheshmurthy
maheshmurthy / index.html
Last active December 7, 2021 21:07
Html file to cast and display votes
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World DApp</title>
<link href='https://fonts.googleapis.com/css?family=Open Sans:400,700' rel='stylesheet' type='text/css'>
<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">
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World DApp</title>
<link href='https://fonts.googleapis.com/css?family=Open Sans:400,700' rel='stylesheet' type='text/css'>
<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">
View index.js
import Web3 from "web3";
import votingArtifact from "../../build/contracts/Voting.json";
let candidates = {"Rama": "candidate-1", "Nick": "candidate-2", "Jose": "candidate-3"}
const App = {
web3: null,
account: null,
voting: null,
@maheshmurthy
maheshmurthy / index.js
Created March 4, 2019 22:09
ethers.js with web3 provider
View index.js
abi = JSON.parse('[{"constant":true,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"totalVotesFor","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"validCandidate","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"votesReceived","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"candidateList","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"candidate","type":"bytes32"}],"name":"voteForCandidate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"candidateNames","type":"bytes32[]"}],"payable":false,"stateMutability":"nonpa
View MyContract.sol
pragma solidity ^0.4.18;
contract MyContract {
mapping(address => uint) totalTokens;
function buy() payable public {
totalTokens[msg.sender] = msg.value;
}
@maheshmurthy
maheshmurthy / sign_vote.js
Last active April 15, 2018 13:59
Ethereum Voting Dapp sign and verify
View sign_vote.js
window.voteForCandidate = function(candidate) {
let candidateName = $("#candidate").val();
let msgParams = [
{
type: 'string', // Any valid solidity type
name: 'Message', // Any string label you want
value: 'Vote for ' + candidateName // The value to sign
}
]