diff --git a/README.md b/README.md index cfce1b6..c9bf1ff 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/cljs_web3/core.cljs b/src/cljs_web3/core.cljs index dbbd8b8..ed652f6 100644 --- a/src/cljs_web3/core.cljs +++ b/src/cljs_web3/core.cljs @@ -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. @@ -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