2

I'm hoping to use the Coinbase Bitcoin Exchange node.js API from inside ClojureScript.

The goal is to replicate the first javascript example on the page:

var CoinbaseExchange = require('coinbase-exchange');
var publicClient = new CoinbaseExchange.PublicClient();

But in my following code I've started by trying to access PublicClient at all:

(ns plutus.core
  (:require
     [cljs.nodejs :as nodejs]))

(def coinb (nodejs/require "coinbase-exchange"))
(nodejs/enable-util-print!)

(defn -main [& args]
  (def pc (js/PublicClient.)))
  (println pc))

(set! *main-cli-fn* -main)

This throws a ReferenceError: PublicClient is not defined, though I've also tried (along with similar variations):

  • (def pc (. coinb (PublicClient)))
  • (def pc (.PublicClient coinb))
  • (def pc (:PublicClient coinb))

All of which have failed by printing nil. I've pretty closely studied this article for any relevant examples, but I'm confused on how using node.js affects the naming of things, if at all.

2 Answers 2

1

Really its not a naming issue, its more about how to use new with nested properties in an object. Unfortunately, you can't get a reference to PublicClient and then new that after the fact.

(new (.-PublicClient coinb))

It does not work even though (.-PublicClient coinb) returns a function.

You need to point to the location of the function, by using it's dot notation within ClojureScript:

(new coinb.PublicClient)
;; OR, more idiomatic
(coinb.PublicClient.)

That should give you what you want.

Sign up to request clarification or add additional context in comments.

Comments

0

Anybody else seeing this?

> ((.-getProducts (cb.PublicClient.)) (fn [_ _ _] nil))
#object[TypeError TypeError: self.makeRelativeURI is not a function]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.