Skip to content

Commit

Permalink
Merge pull request #8 from martinklepsch/instance-maker
Browse files Browse the repository at this point in the history
add function to create web3 instance from injected web3
  • Loading branch information
madvas authored Mar 30, 2018
2 parents 2fb6503 + b1bdd33 commit 361eb96
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ Some functions in `cljs-web3.core` don't really need a web3 instance, even thoug
#### Extra functions for a better life
These are a few extra functions, which you won't find in the Web3 API:
```clojure
;; Create web3 instance
;; Create web3 instance from injected web3 (Mist / Metamask)
(web3/web3)

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

;; Deploy new contract
Expand Down
10 changes: 8 additions & 2 deletions src/cljs_web3/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
(create-web3 \"http://localhost:8545/\"))`
The Web3 JavaScript object is provided on the browser window."
(:require [cljs-web3.utils :as u :refer [js-apply js-prototype-apply]]))

(:require [cljs-web3.utils :as u :refer [js-apply js-prototype-apply]]
[goog.object]))

(def version-api
"Returns a string representing the Ethereum js api version.
Expand Down Expand Up @@ -386,6 +386,12 @@
[web3]
(aget web3 "currentProvider"))

(defn web3
"Return the web3 instance injected via Mist or Metamask"
[]
(new (goog.object/getValueByKeys js/window "web3" "constructor")
(current-provider
(goog.object/get js/window "web3"))))

;;; Providers

Expand Down

0 comments on commit 361eb96

Please sign in to comment.