Example of implementation of EIP 4906 metadata updates
EIP 4096 has an interesting method of updating your metadata with events, more details here. https://eips.ethereum.org/EIPS/eip-4906 So lets see how to implement it with an example. First you need to create a file with interface that has this code in itpragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /// @title EIP-721 Metadata Update Extension interface IERC4906 is IERC165 { /// @dev This event emits when the metadata of a token is changed. /// Third-...

How to get Uniswap V3 liquidity pool address for whitelisting?
Similar to what we did for Uniswap V2 on how to find address of smart contract pool that will be generated we can do the same for V3 https://mirror.xyz/n00b21337.eth/0QkNt3NnLnnUSy4jFmWnaeRr_38Z3wlYKKf1O6URG3c Depending on what chain we are at, you can find all the addresses of Factories here https://github.com/Uniswap/sdk-core/blob/5365ae4cd021ab53b94b0879ec6ceb6ad3ebdce9/src/addresses.ts#L135 Aim for the v3CoreFactoryAddress values.**So there are a few methods to do that, one could be to us...
Clear browser storage when developing
Different wallet scripts usually use window.localStorage for saving data for reuse and determination of what is the status of wallet connect, sometimes this could be awire and you need to clear it, you could delete all in browser like cookies, stored data and all the rest but you can also call first this in consolewindow.localStorage to check what is saved and then you can delete it all withlocalStorage.clear(); orlocalStorage.removeItem("name of localStorage variable you want to remov...
R4Nd0m k0lLEC7I0N 0F U5EFul PHindiN92 0N mY j0URney PhR0m n00b 2 1337. rAmBL1N92 aBoUt 5Ol1d17y, rE4C7, nf7, dEfi, WE83
To make airdrop you need to have a list of addresses that are eligible for that as well as put them into Merkle tree get hashes of them, store them into a smart contract, and then check if they are on the list.
For the node JS part we can use this code to install libraries quickly
const { MerkleTree } = require("merkletreejs");
const keccak256 = require("keccak256");
let whitelistAddress = [
"0x6271217bE872a0F65Bcd8C90d3D0A80B305B8906",
"0xB1620c0542744DeDD30F30a863c09D1964532F8C",
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09",
];
const leafNodes = whitelistAddress.map((addr) => keccak256(addr));
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
const rootHash = merkleTree.getRoot();
const rootHex = merkleTree.getRoot().toString("hex");
let index = whitelistAddress.indexOf(
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09"
);
console.log(index); // returns -1 if not found
const claimingAddress = leafNodes[index];
const hexProof = merkleTree.getHexProof(claimingAddress);
console.log(merkleTree.verify(hexProof, claimingAddress, rootHash));
So we check if the address is in the Merkle tree, we could just check the index on FE part in the list with indexOf() function, we would get index if it is in the list and -1 if the entry is not in the list. But in this example, we will use verify function from Merkle tree library to check if it is there.
In code where we interact with smart contract, we will send these 3 parameters so they will be used directly on the blockchain
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract MerkleTreeExample {
bytes32 public merkleRoot =
0x2e35b61278fbcec3f3b0bb361d928e373e089a61758af09690ce0a5391078ff2;
mapping(address => bool) public whitelistClaimed;
function whitelistMint(bytes32[] calldata _merkleProof) public {
require(!whitelistClaimed[msg.sender], "Address already claimed");
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(
MerkleProof.verify(_merkleProof, merkleRoot, leaf),
"Invalid Merkle Proof."
);
// Add here some MINT function call depending on smart contract
whitelistClaimed[msg.sender] = true;
}
}
So as seen above we need to set merkle tree root hash, which we get in **rootHex **in JS and then we call **whitelistMint **where we check did we already claimed out token and if not we then check sender address and make leaf out of his hex and also pass in merkle proof that needs to be sent as part of transaction. This is something we get from JS library as hexProof variable.
This will all work for situations like NFT where you want jus to check if address is eligible or not, for erc20 tokens aka fungable tokens you will need amounts also to mint/claim in this situation you need to add JS object as data point and process them in conjunction with addresses.We can do it like this
const { MerkleTree } = require("merkletreejs");
const keccak256 = require("keccak256");
let whitelistAddress = {
"0x6271217bE872a0F65Bcd8C90d3D0A80B305B8906": 100,
"0xB1620c0542744DeDD30F30a863c09D1964532F8C": 22,
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09": 44,
};
const leafNodes = Object.entries(whitelistAddress).map(([key, val] = entry) => {
return keccak256(key + val);
});
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
const rootHash = merkleTree.getRoot();
//console.log(rootHash);
const rootHex = merkleTree.getRoot().toString("hex");
const claimingAddress = keccak256(
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09" + 44
);
const hexProof = merkleTree.getHexProof(claimingAddress);
console.log(merkleTree.verify(hexProof, claimingAddress, rootHash));
and in out smart contract we will also need to create leaf where we combine address with amount.
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, amount));
Below links might also help on this task
https://thecibrax.com/using-merkle-trees-for-bulk-transfers-in-ethereum https://steveng.medium.com/performing-merkle-airdrop-like-uniswap-85e43… https://forum.openzeppelin.com/t/how-to-create-a-merkle-tree-and-get-me… https://github.com/Anish-Agnihotri/merkle-airdrop-starter
To make airdrop you need to have a list of addresses that are eligible for that as well as put them into Merkle tree get hashes of them, store them into a smart contract, and then check if they are on the list.
For the node JS part we can use this code to install libraries quickly
const { MerkleTree } = require("merkletreejs");
const keccak256 = require("keccak256");
let whitelistAddress = [
"0x6271217bE872a0F65Bcd8C90d3D0A80B305B8906",
"0xB1620c0542744DeDD30F30a863c09D1964532F8C",
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09",
];
const leafNodes = whitelistAddress.map((addr) => keccak256(addr));
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
const rootHash = merkleTree.getRoot();
const rootHex = merkleTree.getRoot().toString("hex");
let index = whitelistAddress.indexOf(
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09"
);
console.log(index); // returns -1 if not found
const claimingAddress = leafNodes[index];
const hexProof = merkleTree.getHexProof(claimingAddress);
console.log(merkleTree.verify(hexProof, claimingAddress, rootHash));
So we check if the address is in the Merkle tree, we could just check the index on FE part in the list with indexOf() function, we would get index if it is in the list and -1 if the entry is not in the list. But in this example, we will use verify function from Merkle tree library to check if it is there.
In code where we interact with smart contract, we will send these 3 parameters so they will be used directly on the blockchain
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
contract MerkleTreeExample {
bytes32 public merkleRoot =
0x2e35b61278fbcec3f3b0bb361d928e373e089a61758af09690ce0a5391078ff2;
mapping(address => bool) public whitelistClaimed;
function whitelistMint(bytes32[] calldata _merkleProof) public {
require(!whitelistClaimed[msg.sender], "Address already claimed");
bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
require(
MerkleProof.verify(_merkleProof, merkleRoot, leaf),
"Invalid Merkle Proof."
);
// Add here some MINT function call depending on smart contract
whitelistClaimed[msg.sender] = true;
}
}
So as seen above we need to set merkle tree root hash, which we get in **rootHex **in JS and then we call **whitelistMint **where we check did we already claimed out token and if not we then check sender address and make leaf out of his hex and also pass in merkle proof that needs to be sent as part of transaction. This is something we get from JS library as hexProof variable.
This will all work for situations like NFT where you want jus to check if address is eligible or not, for erc20 tokens aka fungable tokens you will need amounts also to mint/claim in this situation you need to add JS object as data point and process them in conjunction with addresses.We can do it like this
const { MerkleTree } = require("merkletreejs");
const keccak256 = require("keccak256");
let whitelistAddress = {
"0x6271217bE872a0F65Bcd8C90d3D0A80B305B8906": 100,
"0xB1620c0542744DeDD30F30a863c09D1964532F8C": 22,
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09": 44,
};
const leafNodes = Object.entries(whitelistAddress).map(([key, val] = entry) => {
return keccak256(key + val);
});
const merkleTree = new MerkleTree(leafNodes, keccak256, { sortPairs: true });
const rootHash = merkleTree.getRoot();
//console.log(rootHash);
const rootHex = merkleTree.getRoot().toString("hex");
const claimingAddress = keccak256(
"0x139Fb3997Ea9d45129b08BC9d8aac5adC0bB3B09" + 44
);
const hexProof = merkleTree.getHexProof(claimingAddress);
console.log(merkleTree.verify(hexProof, claimingAddress, rootHash));
and in out smart contract we will also need to create leaf where we combine address with amount.
bytes32 leaf = keccak256(abi.encodePacked(msg.sender, amount));
Below links might also help on this task
https://thecibrax.com/using-merkle-trees-for-bulk-transfers-in-ethereum https://steveng.medium.com/performing-merkle-airdrop-like-uniswap-85e43… https://forum.openzeppelin.com/t/how-to-create-a-merkle-tree-and-get-me… https://github.com/Anish-Agnihotri/merkle-airdrop-starter
Example of implementation of EIP 4906 metadata updates
EIP 4096 has an interesting method of updating your metadata with events, more details here. https://eips.ethereum.org/EIPS/eip-4906 So lets see how to implement it with an example. First you need to create a file with interface that has this code in itpragma solidity ^0.8.0; import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; /// @title EIP-721 Metadata Update Extension interface IERC4906 is IERC165 { /// @dev This event emits when the metadata of a token is changed. /// Third-...

How to get Uniswap V3 liquidity pool address for whitelisting?
Similar to what we did for Uniswap V2 on how to find address of smart contract pool that will be generated we can do the same for V3 https://mirror.xyz/n00b21337.eth/0QkNt3NnLnnUSy4jFmWnaeRr_38Z3wlYKKf1O6URG3c Depending on what chain we are at, you can find all the addresses of Factories here https://github.com/Uniswap/sdk-core/blob/5365ae4cd021ab53b94b0879ec6ceb6ad3ebdce9/src/addresses.ts#L135 Aim for the v3CoreFactoryAddress values.**So there are a few methods to do that, one could be to us...
Clear browser storage when developing
Different wallet scripts usually use window.localStorage for saving data for reuse and determination of what is the status of wallet connect, sometimes this could be awire and you need to clear it, you could delete all in browser like cookies, stored data and all the rest but you can also call first this in consolewindow.localStorage to check what is saved and then you can delete it all withlocalStorage.clear(); orlocalStorage.removeItem("name of localStorage variable you want to remov...
Share Dialog
Share Dialog
R4Nd0m k0lLEC7I0N 0F U5EFul PHindiN92 0N mY j0URney PhR0m n00b 2 1337. rAmBL1N92 aBoUt 5Ol1d17y, rE4C7, nf7, dEfi, WE83

Subscribe to N00b21337

Subscribe to N00b21337
<100 subscribers
<100 subscribers
No activity yet