forked from kleros/erc-792
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb3.js
32 lines (28 loc) · 831 Bytes
/
web3.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
import Web3 from 'web3'
let web3
window.addEventListener('load', async () => {
// Modern dapp browsers...
if (window.ethereum) {
window.web3 = new Web3(window.ethereum)
try {
// Request account access if needed
await window.ethereum.enable()
// Acccounts now exposed
} catch (_) {
// User denied account access...
}
}
// Legacy dapp browsers...
else if (window.web3) window.web3 = new Web3(web3.currentProvider)
// Acccounts always exposed
// Non-dapp browsers...
else
console.log(
'Non-Ethereum browser detected. You should consider trying MetaMask!'
)
})
if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
console.log('Using the web3 object of the window...')
web3 = new Web3(window.web3.currentProvider)
}
export default web3