# Contract Development on Testnet

When developing smart contracts on Testnet, use the Testnet version of the Cronos Explorer block explorer:

* Cronos Explorer Testnet URL: <https://explorer.cronos.org/testnet>
* Documentation of Cronos Explorer Testnet API: <https://explorer-api-doc.cronos.org/testnet>

## Truffle: Deploy ERC20 Contract

### Step 1. Enter `smart-contract-example/truffle` folder

```bash
$ cd cronos-smart-contract-example/truffle
```

### Step 2. Run `npm install` inside the folder

```bash
$ npm install
```

### Step 3. Make a copy of `.env.example` to `.env`

```bash
$ cp .env.example .env
```

### Step 4. Modify `.env` and fill *ONE* of the field

```bash
MNEMONIC=goose easy ivory ...
PRIVATE_KEY=XXXXXXX
```

### Step 5. Review Migration Script at `migrations/2_deploy_cronos_token.js`

```javascript
  const CronosToken = artifacts.require("CronosToken");
  
  module.exports = function (deployer) {
      deployer.deploy(CronosToken, "Cronos Token", "CRT", "1000000000000000000000000");
  };
```

### Step 6. Endpoints setting

By default, the script will be using your local host `"127.0.0.1"` - If you are not running a localhost, you may leverage the public endpoint `https://evm-t3.cronos.org/` by making changes to `networks` in `truffle-config.js`, for example:

```json
  networks: {
    development: {
      provider: new HDWalletProvider(getHDWallet(), "http://127.0.0.1:8545"), // TODO
      network_id: "*",       // Any network (default: none)
    },
    testnet: {
      provider: new HDWalletProvider(getHDWallet(), "https://evm-t3.cronos.org/"), // TODO
      network_id: "*",
      skipDryRun: true
    },
  },
```

### Step 7. Deploy Contract

```bash
npm run deploy-contract-cronos
```

### Step 8. Obtain Contract address from console and input to Metamask

Correct balance will be shown on Metamask page

![](https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-445915f4c50eec336744d1c79bacc98405116a1d%2Ftruffle_deploy_contract_address.png?alt=media\&token=62c104a9-c013-4601-bb34-df40f7766697)

![](https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-739655cef95a316fae1027e4cf095e96b25fa31f%2Fmetamask_add_tokens.png?alt=media\&token=109c0a7b-7c1e-4a14-8ce1-516e5e535ca6) ![](https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-f9966022821499daa2e44e231bf8d0c642f9f546%2Fmetamask_add_token_success.png?alt=media\&token=82aa0666-ab5e-47c3-9ac1-a76cabab0b43)

## Hardhat: Deploy ERC20 Contract

### Step 1. Enter `smart-contract-example/hardhat` folder

```bash
$ cd smart-contract-example/hardhat
```

### Step 2. Run `npm install` inside the folder

```bash
$ npm install
```

### Step 3. Make a copy of `.env.example` to `.env`

```bash
$ cp .env.example .env
```

### Step 4. Modify `.env` and fill *ONE* of the field

```bash
MNEMONIC=goose easy ivory ...
PRIVATE_KEY=XXXXXXX
```

### Step 5. Review Migration Script at `scripts/deploy-cronos-token.js`

```javascript
  async function main() {
      const CronosToken = await hre.ethers.getContractFactory("CronosToken");
      const cronosToken = await CronosToken.deploy("Cronos Token", "CRT", "1000000000000000000000000");
  
      await cronosToken.deployed();
  
      console.log("CronosToken deployed to:", cronosToken.address);
  }
```

### Step 6. Endpoints setting

By default, the script will be using your local host `"127.0.0.1"` - If you are not running a localhost, you may leverage the public endpoint `https://evm-t3.cronos.org/` by making changes to `networks` in `hardhat.config.js`, for example:

```json
  networks: {
    development: {
      url: "http://localhost:8545",
      accounts: getHDWallet(),
     },
    testnet: {
      url: "https://evm-t3.cronos.org/",
      accounts: getHDWallet(),
    },
  },
```

### Step 7. Deploy Contract

```bash
npm run deploy-contract-cronos
```

### Step 8. Obtain Contract address from console and input to Metamask

Correct balance will be shown on Metamask page

```bash
CronosToken deployed to: 0x5F803c894a0A16B46fe5982fB5D89eb334eAF68
```

![](https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-739655cef95a316fae1027e4cf095e96b25fa31f%2Fmetamask_add_tokens.png?alt=media\&token=109c0a7b-7c1e-4a14-8ce1-516e5e535ca6) ![](https://1786307500-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqXsIo4b4WtOTfICyOIxa%2Fuploads%2Fgit-blob-f9966022821499daa2e44e231bf8d0c642f9f546%2Fmetamask_add_token_success.png?alt=media\&token=82aa0666-ab5e-47c3-9ac1-a76cabab0b43)
