Clojurescript-node.js mount module for a district server, that takes care of setting up and providing web3 instance.
Add
into your project.clj.
Include [district.server.web3] in your CLJS file, where you use mount/start.
Warning: district0x modules are still in early stages, therefore API can change in a future.
You can pass following args to web3 module:
:portPort of locally running ganache or real ethereum client:urlFull url of the client to connect to.:client-configmap of options passed to the websocket client.:reset-connection-poll-intervalIf websocket disconnects or detects an error module callson-offlineand starts polling with this interval (milliseconds) if the connection can be re-created.:on-onlineFunction to be called when connection to the node comes back online.:on-offlineFunction to be called when websocket connection disconnects or throws an error.
(ns my-district
(:require [mount.core :as mount]
[district.server.web3 :refer [web3]]
[cljs-web3.eth :as web3-eth]))
(-> (mount/with-args
{:web3 {:port 8545}})
(mount/start))
(.then (web3-eth/accounts @web3) prn)
;; => ["0x184c2c67dec231c32856e13134670e44f636acc9"]district-server-web3 gets initial args from config provided by district-server-config/config under the key :web3. These args are then merged together with ones passed to mount/with-args.
If you wish to use custom modules instead of dependencies above while still using district-server-web3, you can easily do so by mount's states swapping.
- Build:
npx shadow-cljs compile test-node - Tests:
node out/node-tests.js
- Run headless chrome:
chromium-browser --headless --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --allowed-origins="*" https://chromium.org - Open
chrome://inspect/#devicesand configure remote target with IP ADDRESS (hostname doesn't work)
- Build:
clj -T:build jar - Release:
clj -T:build deploy