forked from WalletConnect/web3modal-vanilla-js-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb3ignite.js
More file actions
executable file
·77 lines (62 loc) · 2.03 KB
/
web3ignite.js
File metadata and controls
executable file
·77 lines (62 loc) · 2.03 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
68
69
70
71
72
73
74
75
76
77
"use strict";
/**
* Example JavaScript code that interacts with the page and Web3 wallets
*/
// Unpkg imports
const Web3Modal = window.Web3Modal.default;
const WalletConnectProvider = window.WalletConnectProvider.default;
const Fortmatic = window.Fortmatic;
const ethProvider = window.frame;
const evmChains = window.evmChains;
// Web3modal instance
let web3Modal
// Chosen wallet provider given by the dialog window
let provider;
// Address of the selected account
let selectedAccount;
/**
* Setup the orchestra
*/
function init() {
console.log("Initializing example");
console.log("WalletConnectProvider is", WalletConnectProvider);
console.log("Fortmatic is", Fortmatic);
console.log("window.web3 is", window.web3, "window.ethereum is", window.ethereum);
// Check that the web page is run in a secure context,
// as otherwise MetaMask won't be available
if(location.protocol !== 'https:') {
// https://ethereum.stackexchange.com/a/62217/620
const alert = document.querySelector("#alert-error-https");
alert.style.display = "block";
//document.querySelector("#btn-connect").setAttribute("disabled", "disabled")
return;
}
// Tell Web3modal what providers we have available.
// Built-in web browser provider (only one can exist at a time)
// like MetaMask, Brave or Opera is added automatically by Web3modal
const providerOptions = {
walletconnect: {
package: WalletConnectProvider, // required
options: {
// Mikko's test key - don't copy as your mileage may vary
infuraId: "8043bb2cf99347b1bfadfb233c5325c0", // required
}
},
frame: {
package: ethProvider // required
},
fortmatic: {
package: Fortmatic,
options: {
// Mikko's TESTNET api key
key: "pk_test_391E26A3B43A3350"
}
}
};
web3Modal = new Web3Modal({
cacheProvider: false, // optional
providerOptions, // required
disableInjectedProvider: false, // optional. For MetaMask / Brave / Opera.
});
console.log("Web3Modal instance is", web3Modal);
}