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

add function to create web3 instance from injected web3 #8

Merged
merged 1 commit into from
Mar 30, 2018

Conversation

martinklepsch
Copy link
Contributor

fix #7

(defn web3
"Return the web3 instance injected via Mist or Metamask"
[]
(new (goog.object/getValueByKeys js/window "web3" "constructor")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used constructor access here as I felt it's a little more explicit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get nil when I call (web3/web3) but I get the proper instance when calling:

(new js/web3.constructor (web3-core/current-provider (goog.object/get js/window "web3")))

Do you have an idea why this could happen?
(I'm in a setup where MetaMask is unlocked etc.)

;; Create web3 instance from injected web3 (Mist / Metamask)
(web3/web3)

;; Create web3 instance from HTTP provider
(web3/create-web3 "http://localhost:8545/")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it would be nice if this actually had http in the name somehow but it's part of the API now so I don't know 🙂

@madvas madvas merged commit 361eb96 into district0x:master Mar 30, 2018
@madvas
Copy link
Collaborator

madvas commented Mar 30, 2018

Thank you!

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 this pull request may close these issues.

Function to obtain web3 instance injected by Mist / Metamask
3 participants