forked from matter-labs/l2-intro-pre-ethdenver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
use-erc721.ts
62 lines (46 loc) · 1.74 KB
/
use-erc721.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
import { Wallet, Provider, Contract } from "zksync-web3";
import { HardhatRuntimeEnvironment } from "hardhat/types";
// load env file
import dotenv from "dotenv";
dotenv.config();
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";
if (!PRIVATE_KEY)
throw "⛔️ Private key not detected! Add it to the .env file!";
// load contract artifact. Make sure to compile first!
import * as ContractArtifact from "../artifacts-zk/contracts/zkNFT.sol/zkNFT.json";
// Address of the contract on zksync testnet
const NFT_TOKEN_ADDRESS = "";
// 0x address where tokens will be minted to
const DESTINATION_WALLET = "";
if (!NFT_TOKEN_ADDRESS) throw "⛔️ ERC721 token address not provided";
// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
console.log(
`Running script to interact with ERC721 contract ${NFT_TOKEN_ADDRESS}`
);
// Initialize the signer.
// @ts-ignore
const provider = new Provider(hre.userConfig.networks?.zkSyncTestnet?.url);
const signer = new Wallet(PRIVATE_KEY, provider);
const tokenContract = new Contract(
NFT_TOKEN_ADDRESS,
ContractArtifact.abi,
signer
);
console.log(
`This collection has ${await tokenContract.totalSupply()} NFTs minted`
);
// mint NFT for wallet
const mintHandle = await tokenContract.safeMint(DESTINATION_WALLET);
// Wait until the transaction is processed on zkSync
await mintHandle.wait();
console.log(`Mint completed in trx ${mintHandle.hash}`);
console.log(
`This collection has ${await tokenContract.totalSupply()} NFTs minted`
);
console.log(
`Account ${DESTINATION_WALLET} owns ${await tokenContract.balanceOf(
DESTINATION_WALLET
)} NFTs`
);
}