Skip to content

Instantly share code, notes, and snippets.

@grachyov
Created March 29, 2019 20:32
Show Gist options
  • Save grachyov/caee1ca2b59cbb8c3d8ff88526e7058c to your computer and use it in GitHub Desktop.
Save grachyov/caee1ca2b59cbb8c3d8ff88526e7058c to your computer and use it in GitHub Desktop.
Detecting Tokenary extension
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