-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdapp.js
More file actions
67 lines (58 loc) · 1.64 KB
/
dapp.js
File metadata and controls
67 lines (58 loc) · 1.64 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
57
58
59
60
61
62
63
64
65
66
67
console.log("hello dapp developers!")
const ssAddress = '0x0489D7b3f9043202277e27dc6E6651798a165B80'
const ssABI = [
{
"inputs": [],
"name": "retrieve",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "num",
"type": "uint256"
}
],
"name": "store",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
window.addEventListener('load', function() {
if (typeof this.window.ethereum !== 'undefined') {
console.log('You have MetaMask. I\'m not that impressed.')
let mmDetected = document.getElementById('mm-detected')
mmDetected.innerHTML = "MetaMask has been detected!"
}
else {
console.log('MetaMask Not Available!')
this.alert("You need to install MetaMask")
}
})
const mmEnable = document.getElementById('mm-connect');
mmEnable.onclick = async () => {
console.log('beep!')
await ethereum.request({method: 'eth_requestAccounts'})
const mmCurrentAccount = document.getElementById('mm-current-account');
mmCurrentAccount.innerHTML = "Here's your current account:"
+ ethereum.selectedAddress
}
const ssSubmit = document.getElementById('ss-input-button');
ssSubmit.onclick = async () => {
const ssValue = document.getElementById('ss-input-box').value;
console.log(ssValue)
var web3 = new Web3(window.ethereum)
const simpleStorage = new web3.eth.Contract(ssABI,ssAddress)
await simpleStorage.methods.store(ssValue).
send({from: ethereum.selectedAddress})
}