Video Demo

Watch a full demonstration of Mega CLI in action:

This demo walks through setting up a a starter project, working with accounts, deploying contracts, and more.

Prerequisites

Before you begin, make sure you have:

  • Installed Mega CLI globally (npm install -g megaeth-cli)
  • Set up Foundry using mega setup
  • Created a local account using mega account create (recommended)

If you haven’t completed these steps yet, see the Installation and Setup guide.

Creating Your First Project

Mega CLI makes it easy to set up a new project with all the necessary configuration for MegaETH.

Create a Full-Stack Project

# Create a new project
mega init my-mega-project

# Navigate to your new project
cd my-mega-project

This creates a full-stack project with both Foundry (for smart contracts) and Next.js (for frontend).

Start the Development Environment

Once your project is created, you can start the development environment:

mega dev

This command starts both:

  • A local Anvil blockchain instance for development
  • The Next.js development server for the frontend

You can also start them individually (recommended):

# Start only the Foundry/Anvil environment
mega dev --foundry

# Start only the Next.js frontend
mega dev --frontend

Deploying Your First Contract

The starter project includes sample contracts you can deploy right away:

  1. First, compile your contracts:
mega compile
  1. Then, deploy to the local development chain:
mega deploy foundry-app/src/GmegaCounter.sol:GmegaCounter --broadcast
  1. Or, deploy to the Mega testnet using your account:
mega deploy foundry-app/src/GmegaCounter.sol:GmegaCounter --broadcast --testnet --account <account-name>

Before deploying to testnet, make sure you have test tokens. You can request them using:

mega faucet --account <account-name>

Checking Account Balance

You can check the balance of your account or any address:

# Check balance of your account
mega balance --account <account-name>

# Check balance of any address
mega balance 0x123...abc

# Show balance in ether instead of wei
mega balance --account dev --ether

Next Steps

Now that you’ve created your first project and explored the basic features, you can:

Troubleshooting

If you encounter any issues:

  • Ensure Foundry is properly installed (mega setup --check)
  • Check that you’re using the latest version of Mega CLI
  • For testnet operations, confirm you have test tokens in your account