Skip to content

Instantly share code, notes, and snippets.

View mbvissers's full-sized avatar
👨‍💻

mbvissers mbvissers

👨‍💻
View GitHub Profile
ul>li*4
<!-- which becomes -->
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
html>head+body>div.header+main+div.footer
<!-- miracously turns into -->
<html>
<head></head>
<body>
<div class="header"></div>
<main></main>
<div class="footer"></div>
</body>
</html>
[default]
src = 'contracts'
libs = ['lib', '../../node_modules']
cache_path = 'foundry-cache'
out = 'foundry-out'
solc_version = '0.8.15'
interface IERC3754 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256);
function ownerOf(uint256 tokenId) external view returns (address);
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address);
function setApprovalForAll(address operator, bool approved) external;
bytes32 public root = 0x11....;
function checkValidity(bytes32[] calldata _merkleProof) public view returns (bool){
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(MerkleProof.verify(_merkleProof, root, leaf), "Incorrect proof");
return true;
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.0;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract Merkle {
// Functions and variables go here...
}
@mbvissers
mbvissers / index.js
Last active September 19, 2022 08:16
const leaf = keccak256('0x123')
const proof = tree.getProof(leaf)
console.log(tree.verify(proof, leaf, root)) //-> true
const root = tree.getRoot().toString('hex')
@mbvissers
mbvissers / index.js
Last active September 19, 2022 08:17
const tree = new MerkleTree(leaves, keccak256, {sortPairs: true})
@mbvissers
mbvissers / index.js
Last active September 19, 2022 08:15
const { MerkleTree } = require('merkletreejs')
const keccak256 = require("keccak256")
const leaves = ['0x789','0x456','0x123'].map(x => keccak256(x))