Last active
March 16, 2018 09:25
-
-
Save xavierlepretre/ed02e9569ff7645bdcfc3b528f233715 to your computer and use it in GitHub Desktop.
Get the Promise of an account on Web3 or Mist.
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
web3.eth.getFirstAccountPromise = function () { | |
// https://gist.github.com/xavierlepretre/ed82f210df0f9300493d5ca79893806a | |
return web3.eth.getAccountsPromise() | |
.then(function (accounts) { | |
if (accounts.length > 0) { | |
return accounts[0]; | |
} else if (typeof(mist) !== "undefined") { | |
// https://gist.github.com/xavierlepretre/ee456323b2544dd4da22cd5fa6d2894c | |
return mist.requestAccountPromise(); | |
} else { | |
throw "No account found"; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment