-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
54 lines (53 loc) · 1.25 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
const MoodContractABI = [
{
inputs: [
{
internalType: "string",
name: "_mood",
type: "string",
},
],
name: "setMood",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "getMood",
outputs: [
{
internalType: "string",
name: "",
type: "string",
},
],
stateMutability: "view",
type: "function",
},
];
const MoodContractAddress = "0xeC70FC4AAc56c45B4548D250e9669C8150396f9A";
let MoodContract;
let signer;
const provider = new ethers.providers.Web3Provider(window.ethereum, "goerli");
provider.send("eth_requestAccounts", []).then(() => {
provider.listAccounts().then((accounts) => {
signer = provider.getSigner(accounts[0]);
MoodContract = new ethers.Contract(
MoodContractAddress,
MoodContractABI,
signer
);
});
});
async function getMood() {
const getMoodPromise = MoodContract.getMood();
const Mood = await getMoodPromise;
document.getElementById("showMood").innerText = `Your Mood: ${Mood}`;
console.log(Mood);
}
async function setMood() {
const mood = document.getElementById("mood").value;
const setMoodPromise = MoodContract.setMood(mood);
await setMoodPromise;
}