Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to obtain web3 instance injected by Mist / Metamask #7

Closed
martinklepsch opened this issue Mar 23, 2018 · 6 comments · Fixed by #8
Closed

Function to obtain web3 instance injected by Mist / Metamask #7

martinklepsch opened this issue Mar 23, 2018 · 6 comments · Fixed by #8

Comments

@martinklepsch
Copy link
Contributor

Hey again :) I was looking through the core namespace and documentation and was just wondering if there's a built in way to obtain the web3 object injected by Metamask et al?

If there's not then maybe it's worth to add this? Not sure how easy this is to uniformly implement across Mist / Metamask /... but currently users need to extern js/window.web3 themselves which introduces some avoidable friction in using this library.

@madvas
Copy link
Collaborator

madvas commented Mar 23, 2018

Hi,
well, web3 object can be always accessed as js/web3, whether it's injected by Mist, MetaMask or any dapp browser. We may add wrapper function around that, but I think it's fairly short notation already.

@martinklepsch
Copy link
Contributor Author

Right. But if you're using advanced compilation and don't have externs via cljsjs then you cannot just use js/web3 but have to use goog.object or some other mechanism to access via string keys.

@madvas
Copy link
Collaborator

madvas commented Mar 26, 2018

yeah, true. I personally always use aget aset js-invoke, so I don't need to care about externs. Another trick is to have cljsjs/web3 just in your project.clj, that will include externs in your compilation, even if you don't :require it in code.

@martinklepsch
Copy link
Contributor Author

aget is for array access and that it works for object access is an implementation detail. So really users should be using goog.object, cljs-oops or some other JS interop tool. Given that there's a variety of ways to do this and given that almost everybody will have to do it I feel like providing this function as part of this library could be beneficial in helping people to get started.

@madvas
Copy link
Collaborator

madvas commented Mar 26, 2018

Sure, I'm bit busy with other work these days, but if you could prepare PR I'll be happy to merge ;) Thank you

@martinklepsch
Copy link
Contributor Author

Sure, I'd be happy to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants