You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/versioned_docs/version-v1.0.0-beta.3/tutorials/noirjs_app.md
+29-59Lines changed: 29 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,23 +14,20 @@ You can find the complete app code for this guide [here](https://github.com/noir
14
14
15
15
## Dependencies
16
16
17
-
Before we start, we want to make sure we have Node installed. For convenience (and speed), we can just install [Bun](https://bun.sh) as our package manager, and Node will work out-of-the-box:
17
+
Before we start, we want to make sure we have Node installed. If you don't have it already you can install it [here](https://nodejs.org/en/download), we recommend using [Yarn](https://yarnpkg.com/getting-started/install) as our package manager for this tutorial.
18
18
19
-
```bash
20
-
curl -fsSL https://bun.sh/install | bash
21
-
```
19
+
We'll also need version 1.0.0-beta.2 nargo installed, see the Noir [installation guide](../getting_started/noir_installation.md) for details.
22
20
23
21
Let's go barebones. Doing the bare minimum is not only simple, but also allows you to easily adapt it to almost any frontend framework.
24
22
25
23
Barebones means we can immediately start with the dependencies even on an empty folder 😈:
26
24
27
25
```bash
28
-
bun i @noir-lang/noir_wasm@1.0.0-beta.2 @noir-lang/noir_js@1.0.0-beta.2 @aztec/bb.js@0.72.1
-`noir_wasm` is the `wasm` version of the Noir compiler. Although most developers prefer to use `nargo` for compiling, there's nothing wrong with `noir_wasm`. We like `noir_wasm`.
34
31
-`noir_js` is the main Noir package. It will execute our program, and generate the witness that will be sent to the backend.
35
32
-`bb.js` is the Typescript interface for Aztec's Barretenberg proving backend. It also uses the `wasm` version in order to run on the browser.
36
33
@@ -77,6 +74,20 @@ This is all that we need to get started with Noir.
77
74
78
75

79
76
77
+
## Compile compile compile
78
+
79
+
Finally we're up for something cool. But before we can execute a Noir program, we need to compile it into ACIR: an abstract representation.
80
+
81
+
This can be done by cd-ing into our circuit directory and running the `nargo compile` command.
82
+
83
+
```bash
84
+
cd circuits
85
+
86
+
nargo compile
87
+
```
88
+
89
+
This will write the compiled circuit into the `target` directory, which we'll then load into our JS later on.
90
+
80
91
## Setting up our app
81
92
82
93
Remember when apps only had one `html` and one `js` file? Well, that's enough for Noir webapps. Let's create them:
@@ -158,72 +169,25 @@ At this point in the tutorial, your folder structure should look like this:
158
169
159
170
:::
160
171
161
-
## Compile compile compile
162
-
163
-
Finally we're up for something cool. But before we can execute a Noir program, we need to compile it into ACIR: an abstract representation. Here's where `noir_wasm` comes in.
164
-
165
-
`noir_wasm` expects a filesystem so it can resolve dependencies. While we could use the `public` folder, let's just import those using the nice `?url` syntax provided by vite. At the top of the file:
Compiling on the browser is common enough that `createFileManager` already gives us a nice in-memory filesystem we can use. So all we need to compile is fetching these files, writing them to our filesystem, and compile. Add this function:
As you can imagine, with `node` it's all conveniently easier since you get native access to `fs`...
191
-
192
-
:::
193
-
194
172
## Some more JS
195
173
196
174
We're starting with the good stuff now. We want to execute our circuit to get the witness, and then feed that witness to Barretenberg. Luckily, both packages are quite easy to work with. Let's import them at the top of the file:
WASMs are not always easy to work with. In our case, `vite` likes serving them with the wrong MIME type. There are different fixes but we found the easiest one is just YOLO instantiating the WASMs manually. Paste this at the top of the file, just below the other imports, and it will work just fine:
Now for the app itself. We're capturing whatever is in the input when people press the submit button. Inside our `try` block, let's just grab that input and get its value. Noir will gladly execute it, and give us a witness:
@@ -257,16 +221,22 @@ Our program is technically **done** . You're probably eager to see stuff happeni
257
221
touch vite.config.js
258
222
```
259
223
260
-
`vite` helps us with a little catch: `bb.js` in particular uses top-level awaits which aren't supported everywhere. So we can add this to the `vite.config.js` to make the bundler optimize them:
224
+
Noir needs to load two WASM modules, but Vite doesn't include them by default in the bundle. We need to add the configuration below to `vite.config.js` to make it work.
225
+
We also need to target ESNext since `bb.js` uses top-level await, which isn't supported in some browsers.
0 commit comments