This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-06
Channels
- # babashka (31)
- # beginners (108)
- # calva (6)
- # clj-kondo (62)
- # cljsrn (5)
- # clojure (29)
- # clojure-australia (2)
- # clojure-europe (17)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (7)
- # clojurescript (25)
- # code-reviews (1)
- # datomic (13)
- # deps-new (7)
- # editors (1)
- # emacs (31)
- # figwheel-main (3)
- # garden (4)
- # graalvm (18)
- # helix (10)
- # improve-getting-started (12)
- # jobs (3)
- # lsp (20)
- # malli (12)
- # off-topic (7)
- # polylith (30)
- # re-frame (10)
- # remote-jobs (2)
- # shadow-cljs (18)
- # spacemacs (5)
- # sql (11)
- # tools-deps (10)
- # vim (9)
- # xtdb (1)
I have the following cljs code where I want to deploy a contract with web3js:
(go (let [web3
(Web3. (.-givenProvider Web3))
ego
(-> (<p! (.. web3 -eth (getAccounts)))
(nth 0))
contract
(new (.. web3 -eth -Contract)
(.-abi (js/JSON.parse contract-json))
nil
(clj->js {:transactionConfirmationBlocks 3}))
contract-deploy
(.. contract
(deploy (clj->js
{:arguments [ipfs]
:data (.-bytecode (js/JSON.parse contract-json))})))]
;;(prn "ego is " ego)
(let [contract-send
(.. contract-deploy
(send (clj->js {:from ego})
(fn [err tx-hash]
(prn "err is " err
"tx hash is " tx-hash))))
contract-instance
(try
(<p!
(.. contract-send
(on "error" (fn [obj] (js/console.log "error " obj)))
(on "sending" (fn [obj] (prn "sending " obj)))
(on "receipt" (fn [receipt]
(prn "contract address is")
(.-contractAddress receipt)))
(on "confirmation" (fn [confirmation-number receipt]
(dispatch [:stop-loading])
(prn "confirmation number"
confirmation-number)
(prn "receipt"
receipt)))))
(catch js/Object e
(.log js/console "contract error " e)))]
(dispatch [:issue-nfts contract-instance
contract-json ego]))))
and for some reason, contract-instance isn’t resolving, which means that the dispatch after it isn’t being called. I don’t know why it isn’t resolving. It was working before and has suddenly stopped working. How to fix this? (The on “sending” part does run)@ps do you have JS code for this as a reference? this is unlikely a CLJS problem, just either some incorrect API usage or incorrect interop
@thheller https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#deploy
can't see the "sending" part there? assuming you mean the (on "sending" ...)
? are you maybe supposed to use that on contract-deploy not contract-send?
@thheller I’m referring to (on “sending” (fn [obj] (prn “sending ” obj)))
That prn occurs
@thheller that sending is from here: https://web3js.readthedocs.io/en/v1.2.11/web3-eth-contract.html#methods-mymethod-send
in this case, mymethod = deploy
yeah no clue. my advice would be to skip the go
stuff and just use .then
. the examples seem to do this too. much easier to spot interop issues that way
don't know anyhthing about the web3 lib you are working with so can't comment on the correctness of any of it
I have tried then too and the stuff within then doesn’t run either (in contract-instance)
How do I use clojure.spec with string keys? (JSON data)
registered specs are always keywords and that's really what s/keys etc are made to work with. so if you want to use those kinds of specs, you'll need to keywordize
you can either do that before applying your specs, or you could do it inside your map specs with s/conform (but this kind of ruins s/form type stuff)
I am trying to read a csv file in clojurescript, this is what I see in my cljs repl - #object[ArrayBuffer [object ArrayBuffer]] - any pointers in reading this will be appreciated.
That's strange - you're supposed to get text out of it because it explicitly uses readAsText
. I would try to debug it first and would probably roll out my own implementation - it would be under 30-5 LOC, no big deal.
That lib is using FileReader
, which does not exist on Node. At least, not in my setup.
@U2FRKM4TW ok let me try debugging it first