# Writing Web3 Apps with Clojurescript

By [ophy.eth](https://paragraph.com/@ophy) · 2021-12-10

---

Clojure has been my favorite language for a long time. It is not without its faults, but it is the language in which I can express my ideas in the most efficient way. It has a powerful macro system that lets you mold the language to your needs. Most Clojure code can run on the JVM as well as in a Javascript runtime (as Clojurescript). This lets us leverage two rich package ecosystems with a convenient lisp syntax.

While much of the code will be self-explanatory, a familiarity with Clojure (or other lisps) will be helpful.

Getting Started
---------------

Writing Clojure code is pretty simple and doesn’t require much boilerplate. We will need a few dependencies though.

### Installing Dependencies

Install Clojure by following this guide:

[https://clojure.org/guides/getting\_started](https://clojure.org/guides/getting_started)

Then install shadow-cljs:

[https://github.com/thheller/shadow-cljs](https://github.com/thheller/shadow-cljs)

### Initialize Project

I like to keep all my projects under `~/Developer`, so I run this from there, but from whichever directory you want to create your project in, run the following code in your terminal:

    npx create-cljs-project hello-web3
    

This will create a new directory called `hello-web3` and within it create some of the files we need to get started.

One of the quirks Clojurescript inherited from Java is namespacing and directory structure.

Create the following file: `src/main/helloweb3/frontend/app.js` and put this in it:

    (ns helloweb3.frontend.app)
    
    (defn init []
      (println "Hello Web3"))
    

In `shadow-cljs.edn`, replace the empty `:builds` map with the following:

    {
    ...
      :builds
      {:frontend
       {:target :browser
        :modules {:main {:init-fn helloweb3.frontend.app/init}}
        }}}
    

Create the file `public/index.html`

    <!doctype html>
    <html>
      <head>
        <meta charset="utf-8" />
        <title>hello web3</title>
      </head>
      <body>
        <div id="root"></div>
        <script src="/js/main.js"></script>
      </body>
    </html>

---

*Originally published on [ophy.eth](https://paragraph.com/@ophy/writing-web3-apps-with-clojurescript)*
