const {MerkleTree} = require("merkletreejs"); // import merkletreejs
const keccak256 = require("keccak256");// import
let whitelistAddresses = [
"0x5B38Da6a701c568545dCfcB03FcB875f56beddC4" ,//A
"OxAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2", //B
"Ox4B20993Bc481177ec7E8f571ceCaE8A9e22C02db",//c
"Ox78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB",//d
let leafNode = whitelistAddresses.map(addr=>keccak256(addr));//key=>value
//console.log(leafNode);
const merkleTree= new MerkleTree (leafNode);//object //console.log(merkleTree);
const rootHash = merkleTree.getRoot();
//console.log (rootHash);
//claiming address const claimingAddress="0×583031D1113aD414F02576BD6afaBfb302140225" ;
// get proof
const hexProof = merkleTree.getProof(claimingAddress);
console. log(hexProof)
//verification
const isProofValid = merkleTree.verify(hexProof, claimingAddress, merkleTree.getRoot());
console.log("Is proof valid?", isProofValid);
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
contract Array {
uint[5] public staticArray = [1, 2, 3]; // Static array
uint[] public dynamicArray = [1, 2]; // Dynamic array
// Addition of array elements
function additionofElements(uint index, uint element) public {
staticArray[index] = element;//static array
dynamicArray.push(element);//dynamic
}
// Deletion of static array element
function deletionofStatic(uint index) public {
delete staticArray[index];
}
// Deletion of dynamic array element
function deletionofDynamic() public {
dynamicArray.pop(); // Remove the last element from the array
}
// Finding length of a given array
function getlength() public view returns (uint, uint) {
return (staticArray.length, dynamicArray.length);
}
//d. Printing array elements in sorted order
function printSortedDynamicArray() public view returns (uint[] memory) {
uint[] memory sortedArray = dynamicArray;
bubbleSort(sortedArray);
return sortedArray;
}
// Simple bubble sort algorithm for sorting the array
//internal so that Frontend can't give input of array
function bubbleSort(uint[] memory arr) internal pure {
uint n = arr.length;
for (uint i = 0; i < n - 1; i++) {
for (uint j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j + 1]
(arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
}
}
}
}
//e. Searching a particular element in an array
function search(uint value) public view returns(bool) {
uint[5] memory array2 = staticArray; //gas optimization
for(uint i=0;i<staticArray.length;i++){
if(array2[i]==value){
return true;
}
}
return false;
}
}