How to add a new EVM network to the CNC Portal - globe-and-citizen/cnc-portal GitHub Wiki

📌 Overview

This guide provides step-by-step instructions on how to add a new EVM-compatible network to the CNC Portal. You will learn how to configure the network settings, update relevant files, and deploy the contracts to the selected network.


🔧 Step 1: Gather Network Details

Before proceeding, collect the required network information:

Parameter Description
Network Name e.g., Example Testnet
Chain ID e.g., 12345
Native Token e.g., EXM
RPC URL e.g., https://rpc.example.com/
Explorer URL e.g., https://explorer.example.com/ (optional)

🛠️ Step 2: Update the Configuration Files

1. Update the Network Types File

Navigate to the network types file:

app/src/types/network.ts 

Add a new entry with the collected details:

export type Networks =
  | 'polygon'
  | 'hardhat'
  | 'sepolia'
  | 'ethereum'
  | 'example' // add your network!
  | 'holesky'
  | undefined;

2. Update the Network Configuration File

Navigate to the network configuration file:

app/src/networks/networks.json

Add a new entry for the network:

"example": {
  "chainId": "0x3039", // Example Chain ID in hex
  "networkName": "Example Testnet",
  "rpcUrl": "https://rpc.example.com",
  "blockExplorerUrl": "https://explorer.example.com",
  "currencySymbol": "EXM"
},

3. Update Wagmi Config

Navigate to wagmi configuration file:

app/src/wagmi.config.ts

Modify the configuration:

import { http, createConfig } from '@wagmi/vue';
import { mainnet, sepolia, polygon, hardhat, exampleChain } from '@wagmi/vue/chains';

export const config = createConfig({
  chains: [mainnet, sepolia, polygon, hardhat, exampleChain],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http('https://sepolia.drpc.org'),
    [polygon.id]: http(),
    [exampleChain.id]: http(), // add this!
    [hardhat.id]: http()
  }
});

4. Add Token Addresses

Navigate to:

app/src/constants/index.ts

Modify the token address mapping:

type ChainTokenAddresses = {
  [key in 137 | 11155111 | 31337 | 12345 /* add this! */]: TokenAddresses;
};

const addressesMap: Record<number, AddressMapping> = {
  11155111: sepolia as AddressMapping,
  31337: hardhat as AddressMapping,
  12345: example as AddressMapping, // add your network
  137: polygon as AddressMapping
};

12345: {
  USDC: '0xYourUSDCAddress', // Example USDC
  USDT: '0xYourUSDTAddress'  // Example USDT
},

🚀 Step 3: Deploy the Contracts

1. Update Hardhat Configuration

Navigate to Hardhat config file:

/contracts/hardhat.config.ts

Add the new network:

example: {
  url: process.env.EXAMPLE_RPC_URL,
  accounts: [process.env.PRIVATE_KEY!],
  chainId: 12345
},

2. Update Environment Variables

Add the following to your .env file in /contracts:

EXAMPLE_RPC_URL=https://rpc.example.com/
PRIVATE_KEY=your_private_key

3. Deploy the Contracts

Run the following commands:

./deploy.sh example
npm run moveConstants

This will sync the deployed contract details with the front-end application.


✅ Conclusion

You have successfully added a new EVM-compatible network to the CNC Portal! The network configuration is now updated, and the contracts are deployed. If you encounter any issues, verify that all configurations are correctly set and try redeploying.