All Projects → district0x → Cljs Web3

district0x / Cljs Web3

Licence: epl-1.0
Clojurescript API for Ethereum Web3 API

Programming Languages

clojure
4091 projects
clojurescript
191 projects

Projects that are alternatives of or similar to Cljs Web3

Typechain
🔌 TypeScript bindings for Ethereum smart contracts
Stars: ✭ 769 (+815.48%)
Mutual labels:  ethereum, web3
Eth Scan
An efficient Ether and token balance scanner library
Stars: ✭ 35 (-58.33%)
Mutual labels:  ethereum, web3
Web3 React
🧰 A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
Stars: ✭ 788 (+838.1%)
Mutual labels:  ethereum, web3
Etherchain Light
Lightweight Ethereum blockchain explorer
Stars: ✭ 550 (+554.76%)
Mutual labels:  ethereum, web3
Trust Wallet Ios
📱 Trust - Ethereum Wallet and Web3 DApp Browser for iOS
Stars: ✭ 1,228 (+1361.9%)
Mutual labels:  ethereum, web3
Ethjs
A highly optimised, light-weight JS utility for Ethereum.
Stars: ✭ 574 (+583.33%)
Mutual labels:  ethereum, web3
Eth.social
An Ethereum dApp for posting social events.
Stars: ✭ 17 (-79.76%)
Mutual labels:  ethereum, web3
Eth Crypto
Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
Stars: ✭ 420 (+400%)
Mutual labels:  ethereum, web3
Connect
(Aragon 1) Seamlessly integrate DAO functionality into web and node.js apps.
Stars: ✭ 81 (-3.57%)
Mutual labels:  ethereum, web3
Web3e
Web3E Ethereum for Embedded devices running Arduino framework
Stars: ✭ 50 (-40.48%)
Mutual labels:  ethereum, web3
Web3.php
A php interface for interacting with the Ethereum blockchain and ecosystem. Native ABI parsing and smart contract interactions.
Stars: ✭ 507 (+503.57%)
Mutual labels:  ethereum, web3
Web Sdk
Portis Web SDK
Stars: ✭ 65 (-22.62%)
Mutual labels:  ethereum, web3
Web3swift
Elegant Web3js functionality in Swift. Native ABI parsing and smart contract interactions on Ethereum network.
Stars: ✭ 462 (+450%)
Mutual labels:  ethereum, web3
Marketprotocol
Ethereum based derivatives trading protocol creating digital tokens for any asset
Stars: ✭ 78 (-7.14%)
Mutual labels:  ethereum, web3
Eattheblocks
Source code for Eat The Blocks, a screencast for Ethereum Dapp Developers
Stars: ✭ 431 (+413.1%)
Mutual labels:  ethereum, web3
Multisignaturewallet
311 byte EIP712 Signing Compliant Delegate-Call Enabled MultiSignature Wallet for the Ethereum Virtual Machine
Stars: ✭ 16 (-80.95%)
Mutual labels:  ethereum, web3
Rimble Ui
React components that implement Rimble's Design System.
Stars: ✭ 357 (+325%)
Mutual labels:  ethereum, web3
React Ethereum Dapp Example
A starter boilerplate for an Ethereum dapp using web3.js v1.0, truffle, react, and parity
Stars: ✭ 384 (+357.14%)
Mutual labels:  ethereum, web3
0x Tracker Client
React single page application which powers the frontend of 0x Tracker
Stars: ✭ 49 (-41.67%)
Mutual labels:  ethereum, web3
Trace
Supply chain transparency platform proof-of-concept based on the Ethereum blockchain ✍️
Stars: ✭ 52 (-38.1%)
Mutual labels:  ethereum, web3

Cljs Web3

ClojureScript API for Ethereum blockchain Web3 API

See also

Installation

;; Add to dependencies
[cljs-web3 "0.19.0-0-11"]
(ns my.app
  (:require [cljsjs.web3] ; You only need this, if you don't use MetaMask extension or Mist browser
            [cljs-web3.bzz :as web3-bzz]
            [cljs-web3.core :as web3]
            [cljs-web3.db :as web3-db]
            [cljs-web3.eth :as web3-eth]
            [cljs-web3.evm :as web3-evm]
            [cljs-web3.net :as web3-net]
            [cljs-web3.personal :as web3-personal]
            [cljs-web3.settings :as web3-settings]
            [cljs-web3.shh :as web3-shh]))

Usage

So basically, stick with the Web3 API docs, all methods there have their kebab-cased version in this library. Also, return values and responses in callbacks are automatically kebab-cased and keywordized. Instead of calling method of the web3 object, you pass it as a first argument. For example:

web3.eth.accounts
web3.version.api
web3.eth.defaultAccount
web3.isConnected()
web3.net.peerCount
web3.net.getPeerCount(function(error, result){ ... })

becomes

(web3-eth/accounts web3)
(web3/version-api web3)
(web3-eth/default-account web3)
(web3/connected? web3)
(web3-net/peer-count web3)
(web3-net/peer-count web3 (fn [error result]))

Some functions in cljs-web3.core don't really need a web3 instance, even though they're called as object methods in Web3 docs. To make our lives easier, in ClojureScript, you can just call it without a web3 instance. For example:

(web3/sha3 "1")
=> 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6
(web3/to-hex "A")
=> 0x41
(web3/to-wei 1 :ether)
=> "1000000000000000000"

Extra functions for a better life

These are a few extra functions, which you won't find in the Web3 API:

;; 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
(web3-eth/contract-new web3 abi
  {:data bin
   :gas gas-limit
   :from (first (web3-eth/accounts w3))}
  (fn [err res]))

;; Create contract instance from already deployed contract
(web3-eth/contract-at web3 abi address)

;; This way you can call any contract method
(web3-eth/contract-call ContractInstance :multiply 5)

;; Gets binary data of a contract method call
(web3-eth/contract-get-data ContractInstance :multiply 5)

;; This library contains the special namespace cljs-web3.evm for controlling a testrpc server
;; See https://github.com/ethereumjs/testrpc for more info
(web3-evm/increase-time! web3 [1000] callback)
(web3-evm/mine! web3 callback)
(web3-evm/revert! web3 [0x01] callback)
(web3-evm/snapshot! web3 callback)

cljs.core.async integration

There's an alternative async namespace for each original namespace, which provides an async alternative instead of the callback approach. For example:

(ns test
  (:require
    [cljs-web3.async.eth :as web3-eth-async]
    [cljs.core.async :refer [<! >! chan]]
    [clojure.string :as string])
  (:require-macros [cljs.core.async.macros :refer [go]]))

(go
  (<! (web3-eth-async/accounts web3))
  ;; returns [nil ["0x56727ca3132d00307051a4fa6c6a2c3f07cb3f91"]]

  ;; Alternatively, you can always pass a core.async channel as a first argument. The response will be put onto this channel
  ;; For example, if you pass a channel with a transducer:
  (<! (web3-eth-async/accounts
            (chan 1 (comp (map second)
                          (map (partial map string/upper-case))))
            web3))
  ;; returns ("0X56727CA3132D00307051A4FA6C6A2C3F07CB3F91")

  )

Code is documentation

Don't hesitate to open lib files or test files of this library to see how to use it. It's not bloated with implementation, so it's easy to read.

Docstrings for the methods and namespaces are adjusted to ClojureScript from the web3.js documentation

DAPPS using cljs-web3

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].