-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (50 loc) · 1.58 KB
/
index.js
File metadata and controls
62 lines (50 loc) · 1.58 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require('dotenv').config();
const { Client, Intents } = require('discord.js');
const { ethers } = require('ethers');
const token = process.env.DISCORD_TOKEN;
const channelId = process.env.CHANNEL_ID;
const guildId = process.env.GUILD_ID;
const nftAddress = process.env.NFT_ADDRESS;
const infuraId = process.env.INFURA_ID;
if (!token) {
throw new Error('Missing process.env.DISCORD_TOKEN');
}
if (!channelId) {
throw new Error('Missing process.env.CHANNEL_ID');
}
if (!nftAddress) {
throw new Error('Missing process.env.NFT_ADDRESS');
}
if (!guildId) {
throw new Error('Missing process.env.GUILD_ID');
}
if (!infuraId) {
throw new Error('Missing process.env.INFURA_ID');
}
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', async () => {
const guild = await client.guilds.cache.get(guildId);
const channel = await guild.channels.cache.get(channelId);
const provider = new ethers.providers.InfuraProvider('mainnet', infuraId);
const loop = async () => {
try {
const token = new ethers.Contract(
nftAddress,
[
'function totalSupply(uint256 id) public view returns (uint256)',
'function MAX_TOKENS() public view returns (uint256)',
],
provider
);
const totalSupply = await token.totalSupply(0);
const maxSupply = await token.MAX_TOKENS();
const str = `Matos NFT: ${totalSupply.toString()}/${maxSupply.toString()}`;
await channel.setName(str);
} catch (e) {
console.error(e);
}
};
loop();
setInterval(loop, 1000 * 60);
});
client.login(token);