-
Notifications
You must be signed in to change notification settings - Fork 3
/
wallet.ts
74 lines (65 loc) · 2.06 KB
/
wallet.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
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { LocalWallet } from "@thirdweb-dev/wallets";
import { Mumbai } from "@thirdweb-dev/chains";
import { readFileSync } from "fs";
import dotenv from "dotenv";
dotenv.config();
const run = async () => {
// create a new wallet for the Mumbai and Goerli testnet
const wallet = new LocalWallet({
chain: Mumbai,
});
const walletAddress = await wallet.generate();
await wallet.connect();
console.log("Wallet address: ", walletAddress);
// connect to the SDK with the wallet using the relayer URL for the Mumbai testnet
const sdk = await ThirdwebSDK.fromWallet(wallet, "mumbai",{
gasless: {
// By specifying a gasless configuration - all transactions will get forwarded to enable gasless transactions
openzeppelin: {
relayerUrl: process.env.RELAYER_URL as string, // your relayer URL
},
},
}
);
// create a new NFT contract
const contractAddress = await sdk.deployer.deployBuiltInContract("nft-collection", {
name: "My NFT Collection",
primary_sale_recipient: walletAddress,
});
console.log("Contract address: ", contractAddress);
const contract = await sdk.getContract(contractAddress);
// create a test user wallet that will receive the NFTs
const userWallet = new LocalWallet({
chain: Mumbai,
});
const userWalletAddress = await userWallet.generate();
console.log("User wallet address: ", userWalletAddress);
// setup metadata for the NFTs that will be minted
const metadatas = [
{
name: "Blue Star",
description: "A blue star NFT",
image: readFileSync("assets/black-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"),
},
];
// mint the NFTs to the user wallet
const tx = await contract.erc721.mintBatchTo(userWalletAddress, metadatas);
console.log("Successfully Minted NFTs to user wallet!!!");
};
run()
.then(() => process.exit(0))
.catch((err) => {
console.error(err);
process.exit(1);
});