-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
78 lines (68 loc) · 2.03 KB
/
script.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
const cornAddress = "0xa0c45509036c422ea7c4d4fcac26a9925531d8c3"
const popCornAddress = "0x6531547b44784dDD8A934fB9fEB92ba582dfeD15"
const popCornMachine = "0x1193d3f5d97e9a8a3B4511a718Eda88C21722B44"
async function setup() {
if (typeof window.ethereum === 'undefined') {
alert("Please install MetaMask or another Ethereum wallet.");
return;
}
await window.ethereum.request({ method: 'eth_requestAccounts' });
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();
const corn = new ethers.Contract(
cornAddress,
[
"function approve(address, uint) external",
],
signer
);
const popcorn = new ethers.Contract(
popCornAddress,
[
"function approve(address, uint) external",
],
signer
);
const poppin = new ethers.Contract(
popCornMachine,
[
"function burnKernel(uint) external",
],
signer
);
const minty = new ethers.Contract(
popCornMachine,
[
"function mint(uint) external",
],
signer
);
return { signer, corn, popcorn, poppin, minty };
}
async function connect(){
await window.ethereum.request({ method: 'eth_requestAccounts' });
}
async function approve() {
const { corn } = await setup();
try {
await corn.approve(popCornMachine, "100000000000000000000000");
} catch (e) { alert(e); }
}
async function approve2() {
const { popcorn } = await setup();
try {
await popcorn.approve(popCornMachine, "100000000000000000000000");
} catch (e) { alert(e); }
}
async function burncorn(_amt) {
const { poppin } = await setup();
try {
await poppin.burnKernel(_amt);
} catch (e) { alert(e); }
}
async function mintnft(_amt) {
const { minty } = await setup();
try {
await minty.mint(_amt);
} catch (e) { alert(e); }
}