Created
March 29, 2019 20:32
-
-
Save grachyov/caee1ca2b59cbb8c3d8ff88526e7058c to your computer and use it in GitHub Desktop.
Detecting Tokenary extension
This file contains 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
window.addEventListener('load', async () => { | |
checkProvider() | |
}); | |
function checkProvider() { | |
if (window.ethereum) { | |
if (window.ethereum.isTokenary) { | |
// Update UI | |
} | |
window.web3 = new Web3(ethereum); | |
try { | |
// Request account access if needed | |
await ethereum.enable(); | |
// Acccounts now exposed | |
web3.eth.sendTransaction({/* ... */}); | |
} catch (error) { | |
// User denied account access... | |
} | |
} else { | |
setTimeout(checkProvider, 100); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment