Coder Social home page Coder Social logo

stjordanis / document-store Goto Github PK

View Code? Open in Web Editor NEW

This project forked from open-attestation/document-store

0.0 2.0 0.0 1.21 MB

Ethereum Smart Contract for OpenCerts Certificate Store

Home Page: https://openattestation.com/docs/verifiable-document/overview

License: Apache License 2.0

JavaScript 75.19% Solidity 16.52% TypeScript 8.29%

document-store's Introduction

Document Store

This repository contains both the smart contract code for document store (in /contracts) as well as the node package for using this library (in /src).

Installing Package

npm i @govtechsg/document-store

Package Usage

To use the package, you will need to provide your own Web3 provider or signer (if you are writing to the blockchain).

Deploying new document store

import {deployAndWait} from "@govtechsg/document-store";

const documentStore = await deployAndWait("My Document Store", signer).then(console.log);

Connecting to existing document store on Ethereum

import {connect} from "@govtechsg/document-store";

const documentStore = await connect("0x4077534e82c97be03a07fb10f5c853d2bc7161fb", providerOrSigner);

Deploying new document store with minimal proxy (TBD - Not available yet)

import {deployMinimal} from "@govtechsg/document-store";

deployMinimal("My Document Store", signer).then(console.log);

Interacting with the document store (example)

const issueMerkleRoot = async () => {
  const documentStore = connect("0x4077534e82c97be03a07fb10f5c853d2bc7161fb", signer);

  const tx = await documentStore.issue("0x7fe0b58ed760804eb7118988637693c4351613be327b56527e55bcd0a8d170d7");
  const receipt = await tx.wait();
  console.log(receipt);

  const isIssued = await instance.isIssued("0x7fe0b58ed760804eb7118988637693c4351613be327b56527e55bcd0a8d170d7");
  console.log(isIssued);
};

List of available functions on contract

documentIssued
documentRevoked
isOwner
name
owner
renounceOwnership
transferOwnership
version
initialize
issue
bulkIssue
getIssuedBlock
isIssued
isIssuedBefore
revoke
bulkRevoke
isRevoked
isRevokedBefore

Provider & Signer

Different ways to get provider or signer:

import {Wallet, providers, getDefaultProvider} from "ethers";

// Providers
const mainnetProvider = getDefaultProvider();
const ropstenProvider = getDefaultProvider("ropsten");
const metamaskProvider = new providers.Web3Provider(web3.currentProvider); // Will change network automatically

// Signer
const signerFromPrivateKey = new Wallet("YOUR-PRIVATE-KEY-HERE", provider);
const signerFromEncryptedJson = Wallet.fromEncryptedJson(json, password);
signerFromEncryptedJson.connect(provider);
const signerFromMnemonic = Wallet.fromMnemonic("MNEMONIC-HERE");
signerFromMnemonic.connect(provider);

Setup

npm install
npm lint
npm test
npm truffle <command>

Contract Benchmark

A benchmark is provided to show the different transaction cost of the different variants of the document store.

npm run benchmark

Benchmark Results

Notes

If you are using vscode, you may need to link the openzeppelin libraries. See https://github.com/juanfranblanco/vscode-solidity#openzeppelin

document-store's People

Contributors

rjchow avatar yehjxraymond avatar nebulis avatar lawliet89 avatar dependabot-preview[bot] avatar gyng avatar

Watchers

James Cloos avatar  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.