-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy path7-airdrop-token.js
More file actions
44 lines (36 loc) · 1.47 KB
/
7-airdrop-token.js
File metadata and controls
44 lines (36 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sdk from "./1-initialize-sdk.js";
// This is the address to our ERC-1155 membership NFT contract.
const editionDrop = sdk.getEditionDrop("0x6288757CC1d20E19d48Fc44C99Eb222C3A2cEAD5");
// This is the address to our ERC-20 token contract.
const token = sdk.getToken("0x6B8f666c5F843056DEfA2ef8124A562E5496d141");
(async () => {
try {
// Grab all the addresses of people who own our membership NFT,
// which has a tokenId of 0.
const walletAddresses = await editionDrop.history.getAllClaimerAddresses(0);
if (walletAddresses.length === 0) {
console.log(
"No NFTs have been claimed yet, maybe get some friends to claim your free NFTs!",
);
process.exit(0);
}
// Loop through the array of addresses.
const airdropTargets = walletAddresses.map((address) => {
// Pick a random # between 1000 and 10000.
const randomAmount = Math.floor(Math.random() * (10000 - 1000 + 1) + 1000);
console.log("✅ Going to airdrop", randomAmount, "tokens to", address);
// Set up the target.
const airdropTarget = {
toAddress: address,
amount: randomAmount,
};
return airdropTarget;
});
// Call transferBatch on all our airdrop targets.
console.log("🌈 Starting airdrop...");
await token.transferBatch(airdropTargets);
console.log("✅ Successfully airdropped tokens to all the holders of the NFT!");
} catch (err) {
console.error("Failed to airdrop tokens", err);
}
})();