Last active
July 22, 2021 01:00
-
-
Save frozeman/fbc7465d0b0e6c1c4c23 to your computer and use it in GitHub Desktop.
Mist web3 loading proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Basically "web3" comes from Mist, | |
but "Web3" CAN come from the dapp. | |
A Dapp has 3 ways to use web3. | |
2. and 3. would work when in Mist and outside. | |
*/ | |
// 1. simply use, web3 comes already defined | |
web3 | |
// 2. optional use web3 from mist, OR load if outside of mist | |
if(typeof web3 === 'undefined') | |
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
// 3. always use web3 provided by the dapp ("Web3" won't be supplied by Mist), but the provider from mist | |
if(typeof web3 !== 'undefined') | |
web3 = new Web3(web3.currentProvider); | |
else | |
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
// Add RPC version? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relying on a global web3 seems to be incompatible with "use strict";