Giter Site home page Giter Site logo

deep-quality-dev / whitelist-mechanism Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 302 KB

whitelist mechanism of primitive/merkle tree/signature methods

Shell 1.57% JavaScript 3.50% Solidity 25.47% TypeScript 69.46%
ethereum whitelist eip712 merkle-tree signature solidity

whitelist-mechanism's Introduction

Smart Contract Whitelist

This project demonstrates the several ways to implement a whitelist mechanism.

Primitive

This is the most primitive way that store whitelist in storage.

It is a quite reasonable and easy way to handle a series of data. To store whitelist in storage, we can simply declare a mapping to record all the valid address that is eligible to whitelist mint. This way will cause a LOT OF GAS, but it will be easier for anyone to test whether certain account is on the whitelist.

Pros: Easy to valid, code, add/remove new address

Cons: Expensive for publisher

Merkle Tree

Merkle tree allows us to compress a list of data of any length into one single hash.

The compressing algorithm works by creating pairs of elements, summing the pairs, and hashing the sums of the pairs. This process repeats, until, we receive a single root hash.

We can compress the data into one hash, and passing this hash onto the contract costs a low amount of gas.

We need to generate merkle tree in the frontend or backend with merkletreejs and take half of the minting process off-chain in order to save gas.

We need to store the root in the contract via solidity function, and on-chain verification with the library MerkleProof. Proof of merkle tree is generated by tree.getHexProof.

Pros: Economic efficient, easy to valid

Cons: Slightly more gas for user to mint, need to reset the root every time to alter the whitelist

Signature

This way is also cheaper than primitive way, but a bit more centralized than previous ways.

We need to set up an address with private key at the backend and keep it credentialed.

Whenever a whitelisted user wishes to mint, we need to verify it at the backend. After verify it, sign the message and pass it back to the user.

User will mint with signature. We can choose proper signing method, e.g. EIP712.

Pros: Cheaper for developers, easier to manage the whitelist at the backend

Cons: More gas require to mint, less decentralized

whitelist-mechanism's People

Contributors

deep-quality-dev avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

nickblockchain

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.