How to create a merkle tree and get merkle root for merkle distributor contract?

Hi, I'm learning how to deploy a Merkle distributor contract. I have looked at some tutorial like https://github.com/aidigidreamers/merkle-distributor/blob/master/src/merkle-tree.ts, and
What to provide in the proof parameter of the verify function for the MerkleProof library

But I'm still feeling a little confused to implement the operation. I don't know how to get Merkle root via Merkle-tree.js and my transactions like blow:
0x001873abd9b26447a7a6ab2e41ddd6a8da3be08a 10000
0x0208bf7897cd6240a6cad7d972f4b8b3b1cd9a5a 1000
0x03377073f2421fc3d9eafe9e235a820c4038ec8b 10000

Please help!

2 Likes

I am not similar with the merkle proof contract, I only know the uniswap token distribution, maybe it can give you some idea.

2 Likes

Thanks for your replying, that’s the idea I referred to. I think the logic of the contract is not complicated, but not familiar with the Merkle proof as well as you. whatever, thanks for your help

1 Like

Hi @uua,

I haven’t played with it beyond what you found: What to provide in the proof parameter of the verify function for the MerkleProof library

I assume you can encode/concatenate the data of the address and the amount of tokens and use the Uniswap example @skyge gave you. (Thanks as always @skyge :pray:)

1 Like

Thanks, I have found the solution of how to generate a Merkle root in Uniswap’s GitHub repo(Merkle Distributor) and love to share it with you:

In short, I need to execute the “generate_merkle_root.tx” file with the following code:
ts-node scripts/generate-merkle-root.ts --input scripts/airdrop_list.json

p.s.
1 airdrop_list.json is customized on my own. It is a white list and the format is the following:

{
  "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f": "100"
}

2 execute the following code on your own computer
npm install -g typescript
npm install -g ts-node

1 Like

Hi @uua,

Thanks for sharing :pray:

For anyone reading this, the script is here:

4 Likes

after generate airdroplist in json and get merkle root, how do i get Uniswap Distributor's smartcontract deployer? i try to generate from deployMerkleDistributor.js it generate smartcontract

  1. npx hardhat compile
  2. ts-node scripts/generate-merkle-root.ts --input scripts/airdrop-winner.json
  3. npx hardhat run --network mumbai scripts/deployMerkleDistributor.js
  4. ts-node scripts/verify-merkle-root.ts --input scripts/result.json
  5. npm run prepublishOnly
  6. ts-node test/MerkleDistributor.test.ts

after to step 6 i got error import { ethers } from 'hardhat'

how do i get a smart contract and transfer my tokens to merkle tree for me to distribute to users

The current recommendation is to use our specially designed library:

Everyone is highly encouraged to use this instead of the earlier recommendations.