-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
77 lines (59 loc) · 2.48 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<title>Hello, Ethers!</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- type="module" treats code as a js module -->
<script type="module">
import { ethers } from "./ethers-5.1.esm.min.js";
//const ethers = require('ethers')
async function mintNFT({contract, ownerAddress, provider, name, description}) {
// First we use the nft.storage client library to add the image and metadata to IPFS / Filecoin
// const client = new NFTStorage({ token: NFT_STORAGE_KEY });
// setStatus("Uploading to nft.storage...")
// const metadata = await client.store({
// name,
// description,
// image,
// });
// setStatus(`Upload complete! Minting token with metadata URI: ${metadata.url}`);
// the returned metadata.url has the IPFS URI we want to add.
// our smart contract already prefixes URIs with "ipfs://", so we remove it before calling the `mintToken` function
const metadataURI = 'https://spacedetention.com/models/metadata.json'
// scaffold-eth's Transactor helper gives us a nice UI popup when a transaction is sent
//const transactor = Transactor(provider, gasPrice);
const tx = await contract.mintToken(ownerAddress, metadataURI);
//setStatus("Blockchain transaction sent, waiting confirmation...");
// Wait for the transaction to be confirmed, then get the token ID out of the emitted Transfer event.
const receipt = await tx.wait();
let tokenId = null;
for (const event of receipt.events) {
if (event.event !== 'Transfer') {
continue
}
tokenId = event.args.tokenId.toString();
break;
}
//setStatus(`Minted token #${tokenId}`);
return tokenId;
}
async function doMinting() {
const provider = new ethers.providers.Web3Provider(window.ethereum);
const minting = await mintNFT(
contract=contract,
ownerAddress=0x7d8D23485217EC8fd2E92dA148BA58a2d2b1670B,
provider=provider,
name="Memory has faded?",
description="Immortal only on the internet");
// Write the greeting result to the DOM.
document.getElementById('output').innerHTML = minting;
}
doMinting();
</script>
</head>
<body>
<div id="output">
</div>
</body>
</html>