-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
75 lines (72 loc) · 1.95 KB
/
index.ts
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
import { config } from "dotenv";
import { readFileSync } from "fs";
import {
createThirdwebClient,
getContract,
sendAndConfirmTransaction,
} from "thirdweb";
import { polygonAmoy } from "thirdweb/chains";
import { deployERC721Contract } from "thirdweb/deploys";
import { lazyMint } from "thirdweb/extensions/erc721";
import { privateKeyToAccount } from "thirdweb/wallets";
config();
const main = async () => {
if (!process.env.WALLET_PRIVATE_KEY) {
throw new Error("No private key found");
}
if (!process.env.THIRDWEB_SECRET_KEY) {
throw new Error("No THIRDWEB_SECRET_KEY found");
}
try {
const chain = polygonAmoy;
const client = createThirdwebClient({
secretKey: process.env.THIRDWEB_SECRET_KEY,
});
const account = privateKeyToAccount({
client,
privateKey: process.env.WALLET_PRIVATE_KEY,
}); // private key account
const address = await deployERC721Contract({
chain,
client,
account,
type: "DropERC721",
params: {
name: "My Drop",
symbol: "MYNFT",
},
});
console.log("Contract address: ", address);
const contract = getContract({ address, chain, client });
const nfts = [
{
name: "Blue Star",
description: "A blue star NFT",
image: readFileSync("assets/blue-star.png"),
},
{
name: "Red Star",
description: "A red star NFT",
image: readFileSync("assets/red-star.png"),
},
{
name: "Yellow Star",
description: "A yellow star NFT",
image: readFileSync("assets/yellow-star.png"),
},
];
const transaction = lazyMint({
contract: contract,
nfts,
});
const data = await sendAndConfirmTransaction({
transaction,
account,
});
console.log("Lazy minted successfully!");
console.log(`Transaction hash: ${data.transactionHash}`);
} catch (err) {
console.error("Something went wrong: ", err);
}
};
main();