Created
March 1, 2017 15:45
-
-
Save ikumasa/67e75591778e127ca705fd8f5ab5e991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns web3test.watch | |
| (:require [cljs.nodejs :as nodejs])) | |
| (enable-console-print!) | |
| (defonce Web3 (nodejs/require "web3")) | |
| (defonce fs (nodejs/require "fs")) | |
| (def web3 (new Web3)) | |
| (.setProvider web3 (new web3.providers.HttpProvider "http://localhost:8545")) | |
| (def eth web3.eth) | |
| (def account (get-in (js->clj eth.accounts) [1])) | |
| (def contractName "simplestorage") | |
| (def contractAddr "0x8c0481e42dd40a717185fe21aafc27fd0c2e981a") | |
| (println (.fromWei web3 (.getBalance eth contractAddr), "ether")) | |
| (def source (.readFileSync fs "test.sol" "utf8")) | |
| (def compiled (.solidity eth.compile source)) | |
| (def contract (.contract eth | |
| (clj->js (get-in (js->clj compiled) [contractName "info" "abiDefinition"])))) | |
| (let [instance (.at contract contractAddr) | |
| efilter (.Set instance (clj->js {:sender account}))] | |
| (println (.get instance)) | |
| (.watch efilter (fn [err event] | |
| (if (nil? err) | |
| (println event) | |
| (println err))))) | |
| (println "watch started") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment