-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (52 loc) · 1.33 KB
/
script.js
File metadata and controls
56 lines (52 loc) · 1.33 KB
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
const EmotionContractAddress = "0x49E438fc7b7e799CCdd184633f1F7b43e9a26970";
const EmotionContractABI = [
{
"inputs": [
{
"internalType": "string",
"name": "_emotion",
"type": "string"
}
],
"name": "setEmotion",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getEmotion",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
];
let EmotionContract;
let signer;
const provider = new ethers.providers.Web3Provider(window.ethereum, "ropsten");// we define provider here
provider.send("eth_requestAccounts", [])
.then(() =>{
provider.listAccounts().then((accounts) =>{
signer = provider.getSigner(accounts[0]);
EmotionContract = new ethers.Contract(
EmotionContractAddress, EmotionContractABI, signer
)
})
})
async function getEmotion(){
const getEmotionPromise = EmotionContract.getEmotion()
const Emotion = await getEmotionPromise;
console.log(Emotion)
}
async function setEmotion(){
const Emotion = document.getElementById("emotion").value;
const setEmotionPromise = EmotionContract.setEmotion(Emotion);
await setEmotionPromise;
console.log("successfully set Emotion")
}