# Smart contracts

## **Node version**

Node >v16.14.X is supported, although Node v18.17.X is recommended.

A `.nvmrc` has been provided if you use `nvm`. You can use this by:

```
nvm use # in ./smart-contracts
```

## **Environment variables**

Before you start, you need to setup the environment variables. Look at the `.env.example` to know what to setup. Env variables required are:

```
PRIVATE_KEY_DEPLOYER=""
ETHERNAL_EMAIL="" # Needed only if using --enable-explorer with DApp Launchpad
ETHERNAL_PASSWORD="" # Needed only if using --enable-explorer with DApp Launchpad
ETHERNAL_WORKSPACE="" # Needed only if using --enable-explorer with DApp Launchpad
```

## **Framework**

The smart contracts run on a [Hardhat](https://hardhat.org/) environment.

The smart contracts are written in [Solidity](https://docs.soliditylang.org/), and are in the `contracts` directory.

Tests are written in JS/TS, and are in `tests` directory. An example test is written for you here.

Scripts are also written in JS/TS, and are in `scripts` directory. Some mandatory scripts are already there to get started with.

## **Deploying on local test chain**

The [`dev`](https://0xpolygon.gitbook.io/dapp-launchpad/commands/dev) command automates everything for you to setup a local test chain.

This will also generate some funded test wallets for you in this test chain, which you can use to develop your DApp.

You may also start this local chain by forking any EVM compatible chain. Just run:

```
dapp-launchpad dev -n NETWORK_NAME -b [BLOCK_NUMBER_TO_FORK_AT]
```

To see all [available options](https://0xpolygon.gitbook.io/dapp-launchpad/commands/dev#options), run:

```
dapp-launchpad dev -h
```

The `dev` command internally runs the provided `scripts/deploy_localhost` script to deploy all contracts in the correct sequence. **When working on your own smart contracts, make sure to update this script.**

## **Local test chain explorer**

Optionally, you can also enable a local blockchain explorer, which auto-indexes all transactions, and provides a feature-loaded dashboard for you to get an overview of this chain.

To use it, run the [`dev`](https://0xpolygon.gitbook.io/dapp-launchpad/commands/dev) command with `-e`, optionally with a few more args.

For this to work, you need to sign up on [Ethernal](https://app.tryethernal.com/), and create a workspace. Then you put your login email, password and workspace name inside the `.env` in `smart-contracts` (checkout the `.env.example`).

The above config can also be mentioned with [`dev`](https://0xpolygon.gitbook.io/dapp-launchpad/commands/dev#options) command params `--ethernal-login-email`, `--ethernal-login-password` and `--ethernal-workspace`, which overrides the env variables.

Once started, you can access the chain explorer at the same URL as mentioned before!

## **Deploying to production**

The [`deploy`](https://0xpolygon.gitbook.io/dapp-launchpad/commands/deploy) command automates everything for you to deploy to any EVM compatible chain.

The `deploy` command internally runs the provided `scripts/deploy_prod` script to deploy all contracts in the correct sequence. When working on your own smart contracts, make sure to update this script.

To see all [available options](https://0xpolygon.gitbook.io/dapp-launchpad/commands/deploy#options), run:

```
dapp-launchpad deploy -h
```

###

<br>
