noir by example

modules

related functions are often grouped in a module

in this example project,

├── Nargo.toml
└── src
   ├── foo.nr
   └── main.nr

the foo module holds some logic

fn hello(x : Field) -> Field {
    x
}

fn hi(x : Field) -> Field {
    x + 1
}

and the main entrypoint can call it

mod foo; // <-- declare the foo module

fn main(x: Field, y: pub Field) {
    assert(x != foo::hello(y));
    assert(x != foo::hi(y));
}

#[test]
fn test_main() {
    main(1, 3);
}

try it out install the noir toolchain if you haven't yet:
        curl -L https://noirup.org/install | bash
        noirup --nightly
        
then checkout and run the example:
        git clone https://github.com/sambarnes/noir-by-example.git
        cd noir-by-example/circuits/examples/modules
        nargo test --show-output
        

prev (structs) next (nested modules)