elekton-contracts | elekton.js | elekton-dapp
A simple JS library to interact with the Elekton smart contracts and IPFS.
Elekton is a set of modules useful to create a simple e-voting system that uses non-interactive zero-knowledge proofs and blockchain technologies to allow users to vote anonymously in a verifiable and transparent way. In addition to this repository there are the Elekton contracts and a simple DApp, which in turn uses elekton.js and allows you to create users, ballots and to vote anonymously.
Notice: The build of this library is a CommonJS module and it has only been used and tested with the create-react-app
scripts, which convert the Node.js modules in order to make the library compatible with browsers.
- 🛠 Install
- 📜 API reference
- 🔬 Development
- 🧾 MIT License
- ☎️ Contacts
You can install elekton package with npm:
npm i elekton --save
or with yarn:
yarn add elekton
- Connecting to backend components
- Creating users
- Retrieving single users
- Retrieving more users
- Retrieving single ballots
- Retrieving more ballots
- Creating ballots
- Voting on ballots
# connect(elektonConfig: ElektonConfig): Elekton
import { connect } from "elekton"
import { abi as contractInterface } from "./contracts/Elekton.json"
const elekton = connect({
contractAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
contractInterface,
wasmFilePath: "https://localhost:3000/main.wasm",
zkeyFilePath: "https://localhost:3000/circuit_final.zkey"
})
# elekton.createUser(userInputData: UserInputData): Promise<User | null>
const user = await elekton.createUser({
name: "Elon",
username: "Musk"
})
# elekton.retrieveUser(privateKeyOrAddressOrIpfsCid: string): Promise<User | null>
const user = await elekton.retrieveUser("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")
# elekton.retrieveUsers(last: number): Promise<User[]>
const [lastUser] = await elekton.retrieveUsers(1)
# elekton.retrieveBallot(index: number): Promise<Ballot>
const ballot = await elekton.retrieveBallot(0)
# elekton.retrieveBallots(last: number): Promise<Ballot[]>
const [lastBallot] = await elekton.retrieveBallots(1)
# user.createBallot(ballotInputData: BallotInputData): Promise<Ballot | null>
const ballot = await user.createBallot({
name: "County elections",
description: "Which hobbit do you want to vote for?",
proposals: ["Frodo Baggins", "Samwise Gamgee", "Pippin Took", "Merry Brandybuck"],
voterPublicKeys: [
"0xb5c911b55d3abf84e4cd1309fa8a9ec26a5a079c11935b96af1656fd514eaf02",
"0x0d5d375a178dad0b3073ff3d5df223c0dc2840e4b417985c87bab671cd50c10d",
"0xd99c2e06fef7db1dd4b96c3afccd36460bfd37e3bd93b1ad4fe7542f2b0ff090",
"0xbd43d085e1fcb553d9bce5dd4bb5e399ff4ccbc3d73d89a7826c9f30a6d58915",
"0x9b2b17399a99664e2f2a0222e3a06ff13ef5cab99324803ad2b1f7124a83a8a4",
"0x22e6c85ac522f2e2529789e4c80873630472883309b8e6539ed7b3fff1fb4a8a"
],
startDate: 1620038490,
endDate: 1620138490
})
# ballot.vote(user: User, vote: number): Promise<void | null>
await ballot.vote(user, 2)
- e-mail : me@cedoor.dev
- github : @cedoor
- website : https://cedoor.dev