# Getting Started

### Creating your project

You can clone the [circomjs-starter](https://github.com/getZeFi/circomjs-starter) repository to get started.

The repository looks like this:

<figure><img src="/files/ucuDeFWFGZ0VS2ppURTF" alt=""><figcaption><p>circom-js starter</p></figcaption></figure>

All of our project's circuits are grouped inside the `./circuits` directory. We have two circuits inside this repository.

* `addition.circom`: checks valid addition of two private inputs.
* `multiplication.circom`: checks valid multiplication of two private inputs.

There is a `src/index.js` file that will be executed as a node js program.&#x20;

#### circuit.config.json

There is a `circuit.config.json` file inside the project root, it is the configuration file for `CircomJS`. This file helps the framework [to find your circuits](/circomjs/circuit-config-file/filename.md) inside the project and build them. The default path for this file is `circuit.config.json` relative to the current working directory.

![](/files/uoSIVj6nUj7ZzLH9Sb12)

You can read more about this file [here](/circomjs/circuit-config-file/circuit-config-file.md).

### Compiling Circuits

To compile your circuit with CircomJS, you need to instantiate a circuit by calling `circomjs.getCircuit()`  function, the function takes in a unique [cID](/circomjs/circuit-config-file/circuit-id.md) { declared inside the config file } and returns the corresponding circuit as a [`Circuit`](/circomjs/classes/circuit.md) instance.

You can then call the `circuit.compile()` method to compile your circuit. Update your `src/index.js` to reflect the following code.

<pre class="language-javascript" data-title="src/index.js" data-line-numbers><code class="lang-javascript">const {CircomJS} = require("@zefi/circomjs")
<strong>
</strong><strong>const main = async() => {
</strong><strong>    const circomjs = new CircomJS()
</strong>    const circuit =  circomjs.getCircuit("mul")
    await circuit.compile()
}

main()
</code></pre>

Running the javascript { `node src/index.js` } file will result in the circuit being compiled and its artifacts being present inside `outputDir/circuitFilename` directory.

> You can try changing the `id` in `circomjs.getCircuit()` to `add`
>
> and you will see the build artifacts of the addition.circom circuit being added to the output directory.

## Generating Proof

Once you have compiled your circuit, you can then start generating proofs out of them.

Every [`Circuit`](/circomjs/classes/circuit.md) instance has a `generateProof` method associated with it, which takes a dynamic input in the following format.

```json
input = {
[key: input signal name]: number
}
```

In our `multiplication.circom` circuit, `x` and `y` are the name of our input signals.

You can continue with the following snippet in `src/index.js` to generate your first proof.

<pre class="language-javascript" data-title="src/index.js" data-line-numbers><code class="lang-javascript">const main = async() => {av
    const circomjs = new CircomJS()
    const circuit =  circomjs.getCircuit("mul")
<strong>
</strong>    // important to await compilation, before running circuit.genProof()
    await circuit.compile()

    const input = {
        x: 3,
        y: 5
    }
    const proof = await circuit.genProof(input);
    console.log(proof)

}

main()
</code></pre>

Run the javascript file again, and you will see ZK proof being logged onto your terminal emulator. The proof is of the following structure.

```
ZKPROOF = {
    proof: {
        pi_a: any,
        pi_b: any,
        pi_c: any,

            protocol: string
        curve: string
    }
    publicSignals: Array<string>
}
```

### Verifying the generated proof

[`Circuit`](/circomjs/classes/circuit.md) instances also has an accompanying `verifyProof()` function that takes as input a ZKProof generated from the `generateProof()` function and returns a boolean indicating the validity of the ZK Proof.

You can continue with the following snippet in `src/index.js` to see the verification in action.

{% code title="" lineNumbers="true" %}

```javascript
const main = async() => {
    const circomjs = new CircomJS()
    const circuit =  circomjs.getCircuit("mul")

    // important to await compilation, before running circuit.genProof()
    await circuit.compile()

    const input = {
        x: 3,
        y: 5
    }
    
    const proof = await circuit.genProof(input);
    
    const res = await circuit.verifyProof(input);
    if(res){
        console.log("verification succeed")
    }
    else{
        console.log("verification failed")
    }

}

main()
```

{% endcode %}

You can now run this javascript file, and you will see "verification succeed" logged onto your terminal emulator!

### CircomJS in your workflow

This section marks the end of this tutorial, but we want to leave you with some ideas on how you can use CircomJS in your daily workflow.

#### Building Circuits

You can use it to build your circuits, rather than relying on writing shell scripts to setup your build, you can declare them in a `circuit.config.json` file, and then make a simple call to `circuit.compile()` to get your builds.

> We are working on adding support for the C-runtime, automatic compilation optimizations and more granular control over the compilation process.

#### Proof generation & verification

CircomJS gives you the ability to generate proofs in a high-level programming language { we also provide typescript types for the framework } and make it simple to consume in applications and verify them!

#### Testing

[CircomJS](/circomjs/introduction/circomjs.md) makes way for easy testing of circuits, you can use the library to test your circuits in a framework of your choice, be it `jest` , `mocha` or any else.

Thanks for going through this page, you can head to the other sections of this Gitbook for more info about CircomJS. Feel free to reach out to us at { <contact@zefi.io> } if you have any feedback.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zefi.gitbook.io/circomjs/introduction/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
