forked from ryanwaits/mint-nft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (43 loc) · 1.41 KB
/
index.js
File metadata and controls
49 lines (43 loc) · 1.41 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
require('dotenv').config();
const { ethers } = require("ethers");
const ABI = require("./ABI.json");
const { privateKey } = require("./privateKey.json");
// change this to the contract you intend to call
const ADDRESS = "0xfcB1315C4273954F74Cb16D5b663DBF479EEC62e";
const GAS_LIMIT = 2000000;
const GAS_PRICE = ethers.utils.parseUnits("666", "gwei");
// make sure more than 1 can actually be minted by a single address
const MAX_AMOUNT = 3;
// change this to represent the minting price
const TOKEN_PRICE = ethers.utils.parseEther("0.08");
const INTERVAL = 500;
// use infura
const provider = new ethers.providers.JsonRpcProvider(process.env.INFURA_API);
const wallet = new ethers.Wallet(privateKey, provider);
const contract = new ethers.Contract(ADDRESS, ABI, wallet);
async function main() {
try {
// make sure the .saleIsActive() function exists on the contract (or equivalent)
const saleIsActive = await contract.saleIsActive();
console.log(saleIsActive);
if (saleIsActive) {
clearInterval(timer);
console.log("LFG");
contract.mintCapsule(TOKEN_PRICE, MAX_AMOUNT, {
gasLimit: GAS_LIMIT,
gasPrice: GAS_PRICE,
nonce: startingNonce,
});
}
} catch (error) {
console.log(error);
}
}
let startingNonce;
let timer;
(async () => {
startingNonce = await provider.getTransactionCount(wallet.address);
timer = setInterval(() => {
main();
}, INTERVAL);
})();