---
# System prepended metadata

title: AleoJS

---

# AleoJS

## Command Line Tool (Anil)

### Commands

#### init
```sh
aleojs init project_name
```
1. This creates the boilerplate .

A sample directory structure is shown below:

```
├── README.md
├── programs
|   └── sample_program.leo
├── artifacts
│   └── sample_program
│       ├── README.md
│       ├── build
│       │   ├── main.aleo
│       │   └── program.json
│       ├── inputs
│       │   └── sample_program.in
│       ├── program.json
│       └── src
│           └── main.leo
├── scripts
│   └── deploy.ts
├── test
│   └── sample_program.test.ts
├── .env.example
├── package-lock.json
└── tsconfig.json

```

#### add
```sh
aleojs add <PROGRAM-NAME>
```
Example:
```
aleojs add s_program
```
> This should call `leo new`

Updated project structure
```
├── README.md
├── programs
|   └── sample_program.leo
|   └── s_program.leo
├── artifacts
│   └── sample_program
│       ├── README.md
│       ├── build
│       │   ├── main.aleo
│       │   └── program.json
│       ├── inputs
│       │   └── sample_program.in
│       ├── program.json
│       └── src
│           └── main.leo
│   └── s_program
│       ├── README.md
│       ├── build
│       │   ├── main.aleo
│       │   └── program.json
│       ├── inputs
│       │   └── s_program.in
│       ├── program.json
│       └── src
│           └── main.leo

├── scripts
│   └── deploy.ts
├── test
│   └── sample_program.test.ts
├── .env.example
├── package-lock.json
└── tsconfig.json

```

#### compile
```sh
aleojs compile 
```
1. This should call `leo run`

#### run

```sh
aleojs run 
```

#### node

```sh
aleojs start node
```
1. Start snarkos node
2. Start aleo-development server

> To start a snarkos node, we require a private key. The private key must be fetched from some config file.


#### run

```sh
aleojs run script_name(.ts) --network network_name
```
1. network_name can be custom and is defined in some config file

> [Example Hardhat Config File](https://github.com/PaulRBerg/hardhat-template/blob/main/hardhat.config.ts)


### Resources

1. Figure out what tools what tools can be used to build the CLI
    a. [Commander.js](https://tj.github.io/commander.js/)
    
2. Upon installation of our tool, that should also automatically install the following of following tools if not installed.
    a. [rust]()
    b. [snarkos]()
    c. [aleo-develop]()
    
    


## Compiler/Transpiler/Interpreter (Sujeet)

Generate four different files after parsing the leo file.
#### a. types.ts
It creates Leo and TS specific types and schema.
[Example](https://github.com/venture23-zkp/gangwar-aleo/blob/main/src/types/gangwar.ts)

#### b. leo2js.ts
Creates conversion logic from leo to TS.
[Example](https://github.com/venture23-zkp/gangwar-aleo/blob/main/src/parsers/leo2js/gangwar.ts)

#### c. js2leo.ts
Creates conversion logic from TS to leo.
[Example](https://github.com/venture23-zkp/gangwar-aleo/blob/main/src/parsers/js2leo/gangwar.ts)

#### d. main.ts
Create functions that's used on Aleo
[Example](https://github.com/venture23-zkp/gangwar-aleo/blob/main/src/services/leo/gangwar.ts)


## Resources
* [Aleo Developer Website](https://developer.aleo.org/getting_started/)
* [Proposal Document]()



# Config File

```javascript
// Filename: aleo-config.js
module.exports = {
    leo: {
        version: "0.11.0"
    },
    // Mode is used to how to run the function/transitions
    // execute: Run with `snarkos developer execute`
    // evaluate: Run with `leo run`
    mode: "execute",
    networks: {
        testnet3: {
            endpoint: "http://localhost:3030/",
            accounts: [process.env.ALEO_PRIVATE_KEY_TESTNET3],
            priorityFee: 0.01
        },
        mainnet: {
            endpoint: "https://api.explorer.aleo.org/v1/",
            accounts: [process.env.ALEO_PRIVATE_KEY_MAINNET],
            priorityFee: 0.001
        }
    },
    defaultNetwork: "testnet3"
};
```

### Changes
1. Private key is network specific.
2. Prioriy fee is given as per network

### Rules
1. If the mode is `evaluate`, networks can be ignored.
2. If the mode is `execute`, networks cannot be ignored. If `networks={}`, throw an error. When running tests or scripts, network can be given as `npm run test --network testnet3`. If `--network` not given, assume network to be the first value in `networks`. 

# Contract.ts

```javascript=25
  constructor(config: ContractConfig = {}) {
    this.config = {
      // infer from aleo-config.js.
      // If not explicitly provided, use the first one as network
      // In the above example, use testnet3 instead of mainnet
      network, 
      // Infer from aleo-config.js as per the network
      privateKey,
      // Generate from privateKey (if required)
      // Seems like not required as it is right now using the PrivateKey in this field
      viewKey,
      // Unchanged
      appName: 'token',
      // Unchanged
      contractPath: 'artifacts/leo/token',
      // Get from aleo-config.js
      fee: '0.01'
    };

```


# `program.json`
Based on the `aleo-config.js` program.json of a program is determined as well.
1. If the program does not have any dependencies, the current workflow works as expected.
2. In case there are dependencies in the program, it should be handled by introducing dependencies in program.json:
```json 
// program.json
{
    "program": "council.aleo",
    "version": "0.0.0",
    "description": "",
    "license": "MIT",
    "dependencies": [
        {
            "name": "bridge.aleo",
            "location": "local",
            "path": "../bridge"
        },
        {
            "name": "wrapped_token.aleo",
            "location": "local",
            "path": "../wrapped_token"
        },
        {
            "name": "token_service.aleo",
            "location": "local",
            "path": "../token_service"
        }
    ]
}

```

If the mode is `evaluate`, the location is `local` and the `path` needs to be set. Path is the relative.

If the mode is `execute`, the location is `network`. It'll have two extra keys - `network` and `endpoint`. An example is shown below:

```json 
// program.json
{
    "program": "council.aleo",
    "version": "0.0.0",
    "description": "",
    "license": "MIT",
    "dependencies": [
        {
            "name": "bridge.aleo",
            "location": "network",
            "network": "testnet3"
            "endpoint": "http:://localhost:3030/"
        },
        {
            "name": "wrapped_token.aleo",
            "location": "network",
            "network": "testnet3",
            "endpoint": "http:://localhost:3030/"
        },
        {
            "name": "token_service.aleo",
            "location": "network",
            "network": "testnet3",
            "endpoint": "http:://localhost:3030/"
        }
    ]
}
```
The `endpoint` and `network` value must be the same as in the `aleo-config.js` file.


