Liking cljdoc? Tell your friends :D

cljs-web3.core

ClojureScript wrapper around Web3 JavaScript API methods on the Web3 object.

A web3-instance can be obtained in two ways:

  1. Via the user's browser (when using Mist or MetaMask)

(defn web3-instance [] (new (aget js/window "Web3") (current-provider (aget js/window "web3"))))

  1. Created via create-web3 (when running a local Ethereum node)

(def web3-instance (create-web3 "http://localhost:8545/"))

The Web3 JavaScript object is provided on the browser window.

ClojureScript wrapper around Web3 JavaScript API methods on the Web3 object.

A `web3-instance` can be obtained in two ways:

1. Via the user's browser (when using Mist or MetaMask)

`(defn web3-instance []
   (new (aget js/window "Web3")
        (current-provider (aget js/window "web3"))))`

2. Created via `create-web3` (when running a local Ethereum node)

`(def web3-instance
   (create-web3 "http://localhost:8545/"))`

The Web3 JavaScript object is provided on the browser window.
raw docstring

address?cljs

(address? address)
(address? Web3 address)

Returns a boolean indicating if the given string is an address.

Parameters: address - An HEX string. Web3 - (Optional first argument) Web3 JavaScript object

Returns false if it's not on a valid address format. Returns true if it's an all lowercase or all uppercase valid address. If it's a mixed case address, it checks using web3's isChecksumAddress().

Example: user> (address? "0x8888f1f195afa192cfee860698584c030f4c9db1") true

;; With first f capitalized user> (web3/address? "0x8888F1f195afa192cfee860698584c030f4c9db1") false

Returns a boolean indicating if the given string is an address.

Parameters:
address - An HEX string.
Web3    - (Optional first argument) Web3 JavaScript object

Returns false if it's not on a valid address format. Returns true if it's an
all lowercase or all uppercase valid address. If it's a mixed case address, it
checks using web3's isChecksumAddress().

Example:
user> `(address? "0x8888f1f195afa192cfee860698584c030f4c9db1")`
true

;; With first f capitalized
user> `(web3/address? "0x8888F1f195afa192cfee860698584c030f4c9db1")`
false
sourceraw docstring

connected?cljs

(connected? web3)

Returns a boolean indicating if a connection to a node exists.

Parameters: web3 - web3 instance callback-fn - callback with two parameters, error and result

Example: user> (connected? web3-instance) true

Returns a boolean indicating if a connection to a node exists.

Parameters:
web3        - web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(connected? web3-instance)`
true
sourceraw docstring

create-web3cljs

(create-web3 url)
(create-web3 Web3 url)

Creates a web3 instance using an http-provider.

Parameters: url - The URL string for which to create the provider. Web3 - (Optional first argument) Web3 JavaScript object

Example: user> (create-web3 "http://localhost:8545/") <web3 instance>

Creates a web3 instance using an `http-provider`.

Parameters:
url  - The URL string for which to create the provider.
Web3 - (Optional first argument) Web3 JavaScript object

Example:
user> `(create-web3 "http://localhost:8545/")`
<web3 instance>
sourceraw docstring

current-providercljs

(current-provider web3)

Will contain the current provider, if one is set. This can be used to check if Mist etc. already set a provider.

Parameters: web3 - web3 instance

Returns the provider set or nil.

Will contain the current provider, if one is set. This can be used to check
if Mist etc. already set a provider.

Parameters:
web3 - web3 instance

Returns the provider set or nil.
sourceraw docstring

from-asciicljs

(from-ascii string)
(from-ascii string padding)
(from-ascii Web3 string padding)

Converts any ASCII string to a HEX string.

Parameters: string - An ASCII string to be converted to HEX. padding - (optional) The number of bytes the returned HEX string should have. Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (from-ascii "ethereum") "0x657468657265756d" user> (from-ascii "ethereum") "0x657468657265756d000000000000000000000000000000000000000000000000"

NOTE: The latter is intended behaviour. Because of a bug in Web3 the padding is not added. See https://github.com/ethereum/web3.js/issues/337

Converts any ASCII string to a HEX string.

Parameters:
string  - An ASCII string to be converted to HEX.
padding - (optional) The number of bytes the returned HEX string should have.
Web3    - (optional first argument) Web3 JavaScript object.

Example:
user> `(from-ascii "ethereum")`
"0x657468657265756d"
user> `(from-ascii "ethereum")`
"0x657468657265756d000000000000000000000000000000000000000000000000"

NOTE: The latter is intended behaviour. Because of a bug in Web3 the padding
      is not added. See https://github.com/ethereum/web3.js/issues/337
sourceraw docstring

from-decimalcljs

(from-decimal number)
(from-decimal Web3 number)

Converts a number or number string to its HEX representation.

Parameters: number - A number to be converted to a HEX string. Web3 - (optional first argument) Web3 JavaScript object.

Example: user-> (web3/from-decimal 21) "0x15"

Converts a number or number string to its HEX representation.

Parameters:
number - A number to be converted to a HEX string.
Web3   - (optional first argument) Web3 JavaScript object.

Example:
user-> `(web3/from-decimal 21)`
"0x15"
sourceraw docstring

from-weicljs

(from-wei number unit)
(from-wei Web3 number unit)

Converts a number of Wei into an Ethereum unit.

Parameters: number - A number or BigNumber instance. unit - One of :noether :wei :kwei :Kwei :babbage :femtoether :mwei :Mwei :lovelace :picoether :gwei :Gwei :shannon :nanoether :nano :szabo :microether :micro :finney :milliether :milli :ether :kether :grand :mether :gether :tether Web3 - (optional first argument) Web3 JavaScript object.

Returns either a number string, or a BigNumber instance, depending on the given number parameter.

Example: user> (web3/from-wei 10 :ether) "0.00000000000000001"

Converts a number of Wei into an Ethereum unit.

Parameters:
number - A number or BigNumber instance.
unit   - One of :noether :wei :kwei :Kwei :babbage :femtoether :mwei :Mwei
         :lovelace :picoether :gwei :Gwei :shannon :nanoether :nano :szabo
         :microether :micro :finney :milliether :milli :ether :kether :grand
         :mether :gether :tether
Web3   - (optional first argument) Web3 JavaScript object.

Returns either a number string, or a BigNumber instance, depending on the
given number parameter.

Example:
user> `(web3/from-wei 10 :ether)`
"0.00000000000000001"
sourceraw docstring

http-providercljs

(http-provider Web3 uri)
source

ipc-providercljs

(ipc-provider Web3 uri)
source

pad-leftcljs

(pad-left string chars)
(pad-left string chars sign)
(pad-left Web3 string chars sign)

Returns input string with zeroes or sign padded to the left.

Parameters: string - String to be padded chars - Amount of chars to address sign - (optional) Char to pad with (behaviour with multiple chars is undefined) Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (web3/pad-left "foo" 8) "00000foo" user> (web3/pad-left "foo" 8 "b") "bbbbbfoo"

Returns input string with zeroes or sign padded to the left.

Parameters:
string - String to be padded
chars  - Amount of chars to address
sign   - (optional) Char to pad with (behaviour with multiple chars is
                    undefined)
Web3   - (optional first argument) Web3 JavaScript object.

Example:
user> `(web3/pad-left "foo" 8)`
"00000foo"
user> `(web3/pad-left "foo" 8 "b")`
"bbbbbfoo" 
sourceraw docstring

pad-rightcljs

(pad-right string chars)
(pad-right string chars sign)
(pad-right Web3 string chars sign)

Returns input string with zeroes or sign padded to the right.

Parameters: string - String to be padded chars - Amount of total chars sign - (optional) Char to pad with (behaviour with multiple chars is undefined) Web3 - (optional first argument) Web3 instance

Example: user> (web3/pad-right "foo" 8) "foo00000" user> (web3/pad-right "foo" 8 "b") "foobbbbb"

Returns input string with zeroes or sign padded to the right.

Parameters:
string - String to be padded
chars  - Amount of total chars
sign   - (optional) Char to pad with (behaviour with multiple chars is
                    undefined)
Web3   - (optional first argument) Web3 instance

Example:
user> `(web3/pad-right "foo" 8)`
"foo00000"
user> `(web3/pad-right "foo" 8 "b")`
"foobbbbb" 
sourceraw docstring

resetcljs

(reset web3)
(reset web3 keep-is-syncing?)

Should be called to reset the state of web3. Resets everything except the manager. Uninstalls all filters. Stops polling.

Parameters: web3 - An instance of web3 keep-is-syncing? - If true it will uninstall all filters, but will keep the web3.eth.isSyncing() polls

Returns nil.

Example: user> (reset web3-instance true) nil

Should be called to reset the state of web3. Resets everything except the manager.
Uninstalls all filters. Stops polling.

Parameters:
web3             - An instance of web3
keep-is-syncing? - If true it will uninstall all filters, but will keep the
                   web3.eth.isSyncing() polls

Returns nil.

Example:
user> `(reset web3-instance true)`
nil
sourceraw docstring

set-providercljs

(set-provider web3 provider)

Should be called to set provider.

Parameters: web3 - Web3 instance provider - the provider

Available providers in web3-cljs:

  • http-provider
  • ipc-provider

Example: user> (set-provider web3-instance (http-provider web3-instance "http://localhost:8545")) nil

Should be called to set provider.

Parameters:
web3     - Web3 instance
provider - the provider

Available providers in web3-cljs:
- `http-provider`
- `ipc-provider`

Example:
user> `(set-provider web3-instance
                     (http-provider web3-instance "http://localhost:8545"))`
nil
sourceraw docstring

sha3cljs

(sha3 string)
(sha3 string options)
(sha3 Web3 string options)

Returns a string representing the Keccak-256 SHA3 of the given data.

Parameters: String - The string to hash using the Keccak-256 SHA3 algorithm Map - (optional) Set encoding to hex if the string to hash is encoded in hex. A leading 0x will be automatically ignored. Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (def hash "Some string to be hashed") #'user/hash user> (sha3 hash) "0xed973b234cf2238052c9ac87072c71bcf33abc1bbd721018e0cca448ef79b379" user> (sha3 hash {:encoding :hex}) "0xbd83a94d23235dd7dfcf67a5a0d9e9643a715cd5b528083a2cf944d61f8e7b51"

NOTE: This differs from the documented result of the Web3 JavaScript API, which equals "0x85dd39c91a64167ba20732b228251e67caed1462d4bcf036af88dc6856d0fdcc"

Returns a string representing the Keccak-256 SHA3 of the given data.

Parameters:
String - The string to hash using the Keccak-256 SHA3 algorithm
Map    - (optional) Set encoding to hex if the string to hash is encoded
                    in hex. A leading 0x will be automatically ignored.
Web3   - (optional first argument) Web3 JavaScript object.

Example:
user> (def hash "Some string to be hashed")
#'user/hash
user> `(sha3 hash)
"0xed973b234cf2238052c9ac87072c71bcf33abc1bbd721018e0cca448ef79b379"`
user> `(sha3 hash {:encoding :hex})`
"0xbd83a94d23235dd7dfcf67a5a0d9e9643a715cd5b528083a2cf944d61f8e7b51"

NOTE: This differs from the documented result of the Web3 JavaScript API,
which equals
"0x85dd39c91a64167ba20732b228251e67caed1462d4bcf036af88dc6856d0fdcc"
sourceraw docstring

to-asciicljs

(to-ascii hex-string)
(to-ascii Web3 hex-string)

Converts a HEX string into a ASCII string.

Parameters: hex-string - A HEX string to be converted to ASCII. Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (to-ascii "0x666f6f") "foo"

Converts a HEX string into a ASCII string.

Parameters:
hex-string - A HEX string to be converted to ASCII.
Web3       - (optional first argument) Web3 JavaScript object.

Example:
user> `(to-ascii "0x666f6f")`
"foo" 
sourceraw docstring

to-big-numbercljs

(to-big-number number-or-hex-string)
(to-big-number Web3 number-or-hex-string)

Converts a given number into a BigNumber instance.

Parameters: number-or-hex-string - A number, number string or HEX string of a number. Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (to-big-number "10000000000000000000") <An instance of BigNumber>

Converts a given number into a BigNumber instance.

Parameters:
number-or-hex-string - A number, number string or HEX string of a number.
Web3                 - (optional first argument) Web3 JavaScript object.

Example:
user> `(to-big-number "10000000000000000000")`
<An instance of BigNumber>
sourceraw docstring

to-decimalcljs

(to-decimal hex-string)
(to-decimal Web3 hex-string)

Returns the number representing a HEX string in its number representation.

Parameters: hex-string - An HEX string to be converted to a number. Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (to-decimal "0x15") 21

Returns the number representing a HEX string in its number representation.

Parameters:
hex-string - An HEX string to be converted to a number.
Web3       - (optional first argument) Web3 JavaScript object.

Example:
user> `(to-decimal "0x15")`
21
sourceraw docstring

to-hexcljs

(to-hex any)
(to-hex Web3 any)

Returns hexadecimal string representation of any value string|number|map|set|BigNumber.

Parameters: Any - The value to parse Web3 - (optional first argument) Web3 JavaScript object.

Example: user> (to-hex "foo") "0x666f6f"

Returns hexadecimal string representation of any value
string|number|map|set|BigNumber.

Parameters:
Any  - The value to parse
Web3 - (optional first argument) Web3 JavaScript object.

Example:
user> `(to-hex "foo")`
"0x666f6f" 
sourceraw docstring

to-weicljs

(to-wei number unit)
(to-wei Web3 number unit)

Converts an Ethereum unit into Wei.

Parameters: number - A number or BigNumber instance. unit - One of :noether :wei :kwei :Kwei :babbage :femtoether :mwei :Mwei :lovelace :picoether :gwei :Gwei :shannon :nanoether :nano :szabo :microether :micro :finney :milliether :milli :ether :kether :grand :mether :gether :tether Web3 - (optional first argument) Web3 JavaScript object.

Returns either a number string, or a BigNumber instance, depending on the given number parameter.

Example: user> (web3/to-wei 10 :ether) "10000000000000000000"

Converts an Ethereum unit into Wei.

Parameters:
number - A number or BigNumber instance.
unit   - One of :noether :wei :kwei :Kwei :babbage :femtoether :mwei :Mwei
         :lovelace :picoether :gwei :Gwei :shannon :nanoether :nano :szabo
         :microether :micro :finney :milliether :milli :ether :kether :grand
         :mether :gether :tether
Web3   - (optional first argument) Web3 JavaScript object.

Returns either a number string, or a BigNumber instance, depending on the
given number parameter.

Example:
user> `(web3/to-wei 10 :ether)`
"10000000000000000000"
sourceraw docstring

version-apicljs

Returns a string representing the Ethereum js api version.

Parameters: Web3 - web3 instance callback-fn - callback with two parameters, error and result

Example: user> (web3/version-node web3-instance (fn [err res] (when-not err (println res)))) nil user> 0.2.0

Returns a string representing the Ethereum js api version.

Parameters:
Web3        - web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(web3/version-node web3-instance
         (fn [err res] (when-not err (println res))))`
nil
user> 0.2.0
sourceraw docstring

version-ethereumcljs

Returns a hexadecimal string representing the Ethereum protocol version.

Parameters: web3 - web3 instance callback-fn - callback with two parameters, error and result

Example: user> (version-ethereum web3-instance (fn [err res] (when-not err (println res)))) nil user> 0x3f

Returns a hexadecimal string representing the Ethereum protocol version.

Parameters:
web3        - web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(version-ethereum web3-instance
         (fn [err res] (when-not err (println res))))`
nil
user> 0x3f
sourceraw docstring

version-networkcljs

Returns a string representing the network protocol version.

"1" is Main Net or Local Net "2" is (Deprecated) Morden Network "3" is Ropsten Test Net "4" is Rinkeby Test Net "42" is Kovan Test Net

Parameters: Web3 - Web3 instance callback-fn - callback with two parameters, error and result

Example: user> (version-network web3-instance (fn [err res] (when-not err (println res)))) nil user> 3

Returns a string representing the network protocol version.

"1"  is Main Net or Local Net
"2"  is (Deprecated) Morden Network
"3"  is Ropsten Test Net
"4"  is Rinkeby Test Net
"42" is Kovan Test Net

Parameters:
Web3        - Web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(version-network web3-instance
         (fn [err res] (when-not err (println res))))`
nil
user> 3
sourceraw docstring

version-nodecljs

Returns a string representing the client/node version.

Parameters: Web3 - web3 instance callback-fn - callback with two parameters, error and result

Example: user> (version-node web3-instance (fn [err res] (when-not err (println res)))) nil user> MetaMask/v3.10.8

Returns a string representing the client/node version.

Parameters:
Web3        - web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(version-node web3-instance
         (fn [err res] (when-not err (println res))))`
nil
user> MetaMask/v3.10.8
sourceraw docstring

version-whispercljs

Returns a string representing the Whisper protocol version.

Parameters: web3 - web3 instance callback-fn - callback with two parameters, error and result

Example: user> (version-whisper web3-instance (fn [err res] (when-not err (println res)))) nil user> 20

Returns a string representing the Whisper protocol version.

Parameters:
web3        - web3 instance
callback-fn - callback with two parameters, error and result

Example:
user> `(version-whisper
         web3-instance
         (fn [err res] (when-not err (println res))))`
nil
user> 20
sourceraw docstring

web3cljs

(web3)

Return the web3 instance injected via Mist or Metamask

Return the web3 instance injected via Mist or Metamask
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close