Guides
NFTs
Airdropping NFTs using Typescript

Airdropping NFTs using Typescript

The airdrop module in the SDK allows you to airdrop NFTs specific mentioned wallet(s), in this guide we will see how to achieve.

Behind the scenes, The NFT is minted based on the metadata provided, and transferred to the wallets of the users specified.

💡

Since you are minting the NFTs from your wallet, you will need to pay the gas fees.

Airdropping is a pretty useful feature! It's used in places to reward users/supporters with perks, such as a Supporter NFT for them.

Now, onto the code.

Setup your project quickly if you haven't yet with the instructions here.

Minting and Airdropping NFTs

To mint and airdrop, we provide a function airdropBatch, that allows you to do so. We also have airdrop function for airdropping to a single user.

Import the modules needed first.

import fs from 'fs';

Next, load the Airdrop module. Deploy one if you don't have any.

const airdropModule = client.getAirdropModule('<AIRDROP_CONTRACT_ADDRESS>');

Finally, do the airdrop.

// Define the list of users to airdrop NFTs to.
const users = ['<USER-1>', '<USER-2>', '<USER-3>'];

try {
  let { transactionHash } = await airdropModule.airdropBatch(users, {
    name: `Airdrop NFT #${i}`,
    description: 'NFT for being a 0xSaturn supporter!',
    image: fs.readFileSync('/path/to/image.png')
  });

  console.log(`Airdropped NFTs. Transaction hash: ${transactionHash}`);
} catch (err) {
  console.log(err);
}

That's it, You've made it to the end. Get started by gifting your supporters with a nice NFT! ✨

Last updated on May 11, 2022