> ## Documentation Index
> Fetch the complete documentation index at: https://thrackle.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy ERC-20 Token

> How to deploy an ERC-20 Token that hooks into the Forte Rules Engine

## Introduction

In this guide, you will learn how to deploy an ERC-20 token contract that hooks into the Forte Rules Engine. The approach will leverage Open Zeppelin's version 4.9.6 contracts package. This guide will deploy to the Base Sepolia testnet, which requires you to have some testnet ETH available.

## Get Started

<Tip>
  If you've already completed the ERC-721 NFT Quickstart, you can skip the next steps and jump to
  the [Deploy ERC-20 Token](#deploy-erc-20-token) section.
</Tip>

Create a copy of this template repository in your own github account by navigating here: [https://github.com/forte-service-company-ltd/fre-tokens-quickstart](https://github.com/forte-service-company-ltd/fre-tokens-quickstart) and clicking the "Use this template" button on GitHub.

<Frame type="simple">
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/thrackle/images/use-template-gh.jpg" alt="Create new repository from template" />
</Frame>

Next, clone the freshly created repository to your local machine:

```bash
git clone https://github.com/<YOUR_GITHUB_USERNAME>/fre-tokens-quickstart
```

### Open in Code Editor

```bash
cd fre-tokens-quickstart
npm install
forge install
cursor .
```

### Setting up the `.env` File

The project includes a `sample.env` to get you started. Copy that to a new file named `.env` and fill in the values.

```bash
cp sample.env .env
```

```bash .env
ETH_RPC_URL=
PRIV_KEY=
TOKEN_ADMIN=
ETHERSCAN_API_KEY=
```

<Accordion title="Environment variable details">
  **ETH\_RPC\_URL** - You can get this from a platform such as Alchemy or Infura. For this demo you'll need an RPC that points to the Base Sepolia testnet.

  **PRIV\_KEY** - This is the private key of a development wallet you control with some testnet ETH on the Base Sepolia network.

  **TOKEN\_ADMIN** - This is the public wallet address of an account that will have admin privileges on the token contract you deploy. For simplicity this could be the public address that is paired with the `PRIV_KEY` variable above.

  **ETHERSCAN\_API\_KEY** - This is optional, but is easy to obtain and enables some easier website based interaction with your token contract. You can create a free API key by logging into [https://basescan.org/](https://basescan.org/) and navigating to the API Keys section.
</Accordion>

Next, make your environment variables available to the command line for running the scripts to deploy your token contract.

```bash
source .env
```

## Deploy ERC-20 Token

An example ERC-20 contract named `QuickstartERC20.sol` is available in the `/src` directory. You can open it up to take a closer look and even apply customizations to meet your needs. Once you're ready to deploy the contract you can do so with the following command (run from the same terminal window you sourced the .env file within).

```bash
forge script script/QuickstartERC20.s.sol:DeployQuickstartERC20 --rpc-url $ETH_RPC_URL --private-key $PRIV_KEY --broadcast --verify
```

This will deploy the contract to the Base Sepolia testnet and publish the source code for it to [https://sepolia.basescan.org](https://sepolia.basescan.org). The terminal where you run the above command will include output similar to the following:

```bash example output {8}
[⠊] Compiling...
[⠑] Compiling 11 files with Solc 0.8.27
[⠘] Solc 0.8.27 finished in 1.64s
Compiler run successful!
Script ran successfully.

== Logs ==
  QuickstartERC20 deployed at: 0x_YOUR_CONTRACT_ADDRESS
```

Notice the highlighted line that indicates the deployed contract address. You can search that on the [testnet explorer](https://sepolia.basescan.org) and even interact with it via the contract tab.

### Test the Mint Function

The mint function is only callable by the `TOKEN_ADMIN` you previously set in the environment file. Test out calling this function and minting yourself some test tokens.

```bash
cast send 0x_YOUR_CONTRACT_ADDRESS "mint(address,uint256)" $TOKEN_ADMIN 10000000000000000000000 --private-key $PRIV_KEY --rpc-url $ETH_RPC_URL
```

### Check Balance

You'll see some output in the terminal indicating the status of the contract call. When successful you can refresh the transactions tab on the testnet explorer to see your transaction indexed there as well.

Check the balance of your wallet to ensure those tokens were minted:

```bash
cast call 0x_YOUR_CONTRACT_ADDRESS "balanceOf(address)(uint256)" $TOKEN_ADMIN --rpc-url $ETH_RPC_URL
```

## Next Steps

Now that you have a rules ready ERC-20 token deployed it's time to deploy the client specific contracts that connect this token to the Forte Rules Engine!
