This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 790
/
mint.js
114 lines (105 loc) · 3.06 KB
/
mint.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const HDWalletProvider = require("truffle-hdwallet-provider");
const web3 = require("web3");
const MNEMONIC = process.env.MNEMONIC;
const NODE_API_KEY = process.env.INFURA_KEY || process.env.ALCHEMY_KEY;
const isInfura = !!process.env.INFURA_KEY;
const FACTORY_CONTRACT_ADDRESS = process.env.FACTORY_CONTRACT_ADDRESS;
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS;
const OWNER_ADDRESS = process.env.OWNER_ADDRESS;
const NETWORK = process.env.NETWORK;
const NUM_CREATURES = 12;
const NUM_LOOTBOXES = 4;
const DEFAULT_OPTION_ID = 0;
const LOOTBOX_OPTION_ID = 2;
if (!MNEMONIC || !NODE_API_KEY || !OWNER_ADDRESS || !NETWORK) {
console.error(
"Please set a mnemonic, Alchemy/Infura key, owner, network, and contract address."
);
return;
}
const NFT_ABI = [
{
constant: false,
inputs: [
{
name: "_to",
type: "address",
},
],
name: "mintTo",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
];
const FACTORY_ABI = [
{
constant: false,
inputs: [
{
name: "_optionId",
type: "uint256",
},
{
name: "_toAddress",
type: "address",
},
],
name: "mint",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
];
async function main() {
const network =
NETWORK === "mainnet" || NETWORK === "live" ? "mainnet" : "rinkeby";
const provider = new HDWalletProvider(
MNEMONIC,
isInfura
? "https://" + network + ".infura.io/v3/" + NODE_API_KEY
: "https://eth-" + network + ".alchemyapi.io/v2/" + NODE_API_KEY
);
const web3Instance = new web3(provider);
if (FACTORY_CONTRACT_ADDRESS) {
const factoryContract = new web3Instance.eth.Contract(
FACTORY_ABI,
FACTORY_CONTRACT_ADDRESS,
{ gasLimit: "1000000" }
);
// Creatures issued directly to the owner.
for (var i = 0; i < NUM_CREATURES; i++) {
const result = await factoryContract.methods
.mint(DEFAULT_OPTION_ID, OWNER_ADDRESS)
.send({ from: OWNER_ADDRESS });
console.log("Minted creature. Transaction: " + result.transactionHash);
}
// Lootboxes issued directly to the owner.
for (var i = 0; i < NUM_LOOTBOXES; i++) {
const result = await factoryContract.methods
.mint(LOOTBOX_OPTION_ID, OWNER_ADDRESS)
.send({ from: OWNER_ADDRESS });
console.log("Minted lootbox. Transaction: " + result.transactionHash);
}
} else if (NFT_CONTRACT_ADDRESS) {
const nftContract = new web3Instance.eth.Contract(
NFT_ABI,
NFT_CONTRACT_ADDRESS,
{ gasLimit: "1000000" }
);
// Creatures issued directly to the owner.
for (var i = 0; i < NUM_CREATURES; i++) {
const result = await nftContract.methods
.mintTo(OWNER_ADDRESS)
.send({ from: OWNER_ADDRESS });
console.log("Minted creature. Transaction: " + result.transactionHash);
}
} else {
console.error(
"Add NFT_CONTRACT_ADDRESS or FACTORY_CONTRACT_ADDRESS to the environment variables"
);
}
}
main();