Git Product home page Git Product logo

merkletree-whitelist-nft's Introduction

MerkleTree WhiteList NFT

193118010-2a9f5129-6232-42bd-8efe-dfb29753508e

Simple implementation of a Merkle Tree Whitelist for an NFT smart contract.


Libraries used to generate the Merkle tree and verify a wallet is inside of the Merkle tree with the proof:

  • keccak256
npm i keccak256
  • MerkleTreejs
npm i merkletreejs

merkleTree.js

const { MerkleTree } = require("merkletreejs");
const keccak256 = require("keccak256");
const wallet = keccak256("0x5B38Da6a701c568545dCfcB03FcB875f56beddC4");

const leaves = [
  "0x5B38Da6a701c568545dCfcB03FcB875f56beddC4",
  "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
  "0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7",
  "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
  "0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7",
];

// Create Root.
const tree = new MerkleTree(leaves, keccak256, {
  /** If set to `true`, the leaves will hashed using the set hashing algorithms. */
  hashLeaves: true,
  /** If set to `true`, the hashing pairs will be sorted. */
  sortPairs: true,
});

// Get root hash of the tree.
const root = tree.getHexRoot();

// Get Proof from the root hash.
const proof = tree.getHexProof(wallet);

//Solidity needs it to have " double quotes" instead of `single quotes`
const merkleProof = [
  "0x9da258265696d227eef589fd6cd14671a82aa2963ec2214eb048fca5441c4a7e",
  "0xcf1af5889bea11e72fa5ccf227f07abc63b97b8f599e45dff51bb45c16a680bd",
  "0xbedabe7d0bfc2ec1d2a619d63dff4699d816c857675c1cd6ce376dd39ab5d092",
  "0x1c6df1b72628f8ee596a55eaa3078be04c45ce70bd92b04a719c065f92165690",
  "0x42d2024a9a9eb2572b5985038caf67e7af6228905cef6f38fe929b40f5c73d46",
];

module.exports = { merkleProof, root, wallet };

Development

Install dependencies

npm install

Test the contract by passing an address in the Whitelist and an addres not in the Whitelist

npx hardhat test

merkletree-whitelist-nft's People

Contributors

bytes0xcr6 avatar

Stargazers

 avatar

Watchers

 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.