-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupply.js
More file actions
53 lines (40 loc) · 1.6 KB
/
supply.js
File metadata and controls
53 lines (40 loc) · 1.6 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
// Import web3 library
const Web3 = require('web3');
// Connect to an Ethereum node
const web3 = new Web3('YOUR_NODE_URL');
// Define ERC20 interface
const ERC20 = require('./ERC20.json');
// Define token contract address
const tokenAddress = 'TOKEN_ADDRESS';
// Create token contract instance
const tokenContract = new web3.eth.Contract(ERC20, tokenAddress);
// Define addresses that hold non-circulating tokens
const nonCirculatingAddresses = ['CONTRACT_ADDRESS', 'CONTRACT_ADDRESS'];
// Get total supply of tokens
tokenContract.methods.totalSupply().call().then(totalSupply => {
// Convert total supply from wei to ether
totalSupply = web3.utils.fromWei(totalSupply);
// Initialize circulating supply as total supply
let circulatingSupply = totalSupply;
// Initialize array to store promises for balance calls
let balancePromises = [];
// Loop through non-circulating addresses and add promises for balance calls
for (let address of nonCirculatingAddresses) {
let balancePromise = tokenContract.methods.balanceOf(address).call().then(balance => {
// Convert balance from wei to ether
balance = web3.utils.fromWei(balance);
// Return balance as a number
return Number(balance);
});
balancePromises.push(balancePromise);
}
// Wait for all balance calls to finish
Promise.all(balancePromises).then(balances => {
// Subtract balances from circulating supply
for (let balance of balances) {
circulatingSupply -= balance;
}
// Log circulating supply in console
console.log('Circulating Supply: ' + circulatingSupply + ' tokens');
});
});