How to generate merkle root for airdrop contract using SDK

In this guide, we will explore how to generate a Merkle root for thirdweb’s airdrop contract.

 

The new thirdweb v5 SDK provides extensions to generate a Merkle root for the airdrop contract, applicable for all three available contract types: ERC-20, ERC-721 and ERC-1155.

FOR ERC-20

import { generateMerkleTreeInfoERC20 } from "thirdweb/extensions/airdrop";

// snapshot / allowlist of airdrop recipients and amounts
const snapshot = [
  { recipient: "0x...", amount: 10 },
  { recipient: "0x...", amount: 15 },
  { recipient: "0x...", amount: 20 },
];

const tokenAddress = "0x..."; // Address of ERC20 airdrop token

const { merkleRoot, snapshotUri } = await generateMerkleTreeInfoERC20(
  {
    contract,
    tokenAddress,
    snapshot,
  },
);
 

FOR ERC-721

import { generateMerkleTreeInfoERC721 } from "thirdweb/extensions/airdrop";

// snapshot / allowlist of airdrop recipients and amounts
const snapshot = [
  { recipient: "0x...", tokenId: 0 },
  { recipient: "0x...", tokenId: 1 },
  { recipient: "0x...", tokenId: 2 },
];

const tokenAddress = "0x..."; // Address of ERC721 airdrop token

const { merkleRoot, snapshotUri } =
  await generateMerkleTreeInfoERC721({
    contract,
    tokenAddress,
    snapshot,
  });
 

FOR ERC-1155

import { generateMerkleTreeInfoERC1155 } from "thirdweb/extensions/airdrop";

// snapshot / allowlist of airdrop recipients and amounts
const snapshot = [
  { recipient: "0x...", tokenId: 0, amount: 10 },
  { recipient: "0x...", tokenId: 1, amount: 12 },
  { recipient: "0x...", tokenId: 2, amount: 15 },
];

const tokenAddress = "0x..."; // Address of ERC1155 airdrop token

const { merkleRoot, snapshotUri } =
  await generateMerkleTreeInfoERC1155({
    contract,
    tokenAddress,
    snapshot,
  });
 

Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.

Did this answer your question?
😞
😐
🤩