Skip to content

Instantly share code, notes, and snippets.

jackleslie / provider-enable-promise.js
Last active October 21, 2018 13:01
Example provider enablement code for EIP-1102 (promise version)
View provider-enable-promise.js
Promise.resolve(window.web3 || window.ethereum)
.then(() => {
// using this will wrap the return values in promises despite the first condition being synchronous
return window.web3.eth.defaultAccount || window.ethereum.enable();
.then(account => {
// either method will return the default account address
.catch(err => {
// no web3 or ethereum

Keybase proof

I hereby claim:

  • I am jackleslie on github.
  • I am jackleslie ( on keybase.
  • I have a public key ASBawO-etYcX-mx9UVlkyV8AmGcXg3jbx-jpc7KS5X5xzQo

To claim this, I am signing this object: