-
Notifications
You must be signed in to change notification settings - Fork 0
/
dapp.js
35 lines (29 loc) · 1.01 KB
/
dapp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const [accounts, setAccounts] = useState([]);
useEffect(() => {
requestAccount();
}, [])
async function requestAccount() {
if(typeof window.ethereum !== 'undefined') {
let accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })
setAccounts(accounts);
}
}
const { MerkleTree } = require('merkletreejs');
const keccak256 = require('keccak256');
useEffect(() => {
requestAccount();
}, [])
async function requestAccount() {
if(typeof window.ethereum !== 'undefined') {
let accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })
setAccounts(accounts);
}
}
const { MerkleTree } = require('merkletreejs')
const keccak256 = require('keccak256')
let Whitelist = require('./Accounts.json')
const leafNodes = Whitelist.map(addr => keccak256(addr));
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true});
const rootHash = merkleTree.getRoot();
const claimingAddress = keccak256(accounts[0]);
const hexProof = merkleTree.getHexProof(claimingAddress);