Fork me on GitHub
#clojurescript
<
2021-09-06
>
zendevil.eth07:09:46

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)

thheller09:09:23

@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

thheller09:09:01

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?

zendevil.eth10:09:38

@thheller I’m referring to (on “sending” (fn [obj] (prn “sending ” obj)))

zendevil.eth10:09:45

That prn occurs

zendevil.eth10:09:43

in this case, mymethod = deploy

thheller10:09:28

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

thheller10:09:27

don't know anyhthing about the web3 lib you are working with so can't comment on the correctness of any of it

zendevil.eth11:09:50

I have tried then too and the stuff within then doesn’t run either (in contract-instance)

Pepijn de Vos13:09:51

How do I use clojure.spec with string keys? (JSON data)

Alex Miller (Clojure team)13:09:56

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

Alex Miller (Clojure team)13:09:58

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)

murtaza5217:09:50

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.

p-himik17:09:10

How do you read the file?

murtaza5218:09:37

using the following lib - jtk-dvlp/re-frame-readfile-fx

p-himik18:09:21

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.

borkdude18:09:29

is this node btw, or browser?

p-himik18:09:02

That lib is using FileReader, which does not exist on Node. At least, not in my setup.

murtaza5218:09:31

@U2FRKM4TW ok let me try debugging it first

murtaza5210:09:02

@U2FRKM4TW thanks, that resolved it, its reading it as plain text.

👍 2
p-himik10:09:30

So what did it end up being? How did you get an array buffer in the first place?

murtaza5210:09:05

it was existing code which was reading excel file, I thought thats default that all files are read as arraybuffer ... but as u pointed out it should be plain text so I dug through the code.

👍 2