Code Monkey home page Code Monkey logo

elekton.js's Introduction

elekton-contracts | elekton.js | elekton-dapp

ElektonJS

A simple JS library to interact with the Elekton smart contracts and IPFS.

NPM version Github license Linter eslint Code style prettier Repository top language

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.


Table of Contents

Install

npm or yarn

You can install elekton package with npm:

npm i elekton --save

or with yarn:

yarn add elekton

API reference

# 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)

Contacts

Developers

elekton.js's People

Contributors

cedoor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.