Skip to content

awesamarth/mega-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mega CLI

A complete development environment for the Mega blockchain. This CLI streamlines the development workflow for smart contract developers, frontend developers, and full-stack developers working with the Mega testnet.

NPM Version License: MIT

Features

  • Project templating: Create boilerplate projects for smart contract, frontend, or full-stack development
  • Development environment: Easily start local blockchain or frontend development servers
  • Account management: Create, import, and manage blockchain accounts
  • Smart contract operations: Compile, deploy, and verify contracts on Mega testnet
  • MegaETH operations: Check balances and request tokens from faucet
  • Foundry: Many Mega CLI commands are wrappers around Foundry (Anvil, Forge, Cast, Chisel) commands

Installation

# Install globally using npm
npm install -g megaeth-cli

# Or using yarn
yarn global add megaeth-cli

# Or using pnpm
pnpm add -g megaeth-cli

Dependencies

Mega CLI requires Foundry for smart contract development functionality. You can install it by running:

mega setup

Quick Start

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

# Start the development environment
cd my-mega-project
mega dev

Command Reference

Project Creation

# Create a full-stack project (NextJS + Foundry)
mega init 
#or
mega init [project-name]

# Create a frontend-only project (NextJS + WalletConnect)
mega init --frontend

# Create a Foundry-only project configured for Mega testnet
mega init --foundry

Development Environment

# Start both frontend and Foundry environments
mega dev

# Start just the NextJS app
mega dev --frontend

# Start just the Foundry/Anvil local chain
mega dev --foundry

Account Management

# Create a new account/wallet
mega account create

# Import an existing account
mega account import

# List all managed accounts
mega account list

# Check ETH balance for address
mega balance [address]

# Check ETH balance for a stored account
mega balance --account <name>

Contract Development

# Compile Solidity contracts
mega compile

# Deploy a contract
mega deploy <path-to-contract>/<contract-file-name>.sol:<contract-name> --broadcast --testnet --account <keystore-account-name>
#or, with private keys
mega deploy <path-to-contract>/<contract-file-name>.sol:<contract-name> --broadcast --testnet --private-key <private-key>



# Deploy to local network instead of testnet
mega deploy <path-to-contract>/<contract-file-name>.sol:<contract-name> --broadcast 

# Verify a contract on block explorer
mega verify  <contract address> --watch --etherscan-api-key <your-etherscan-api-key> <path-to-contract>/<contract-file-name>.sol:<contract-name>

Network Operations (WIP)

# Request test tokens from faucet
mega faucet <address>

Utility Commands

# Check and set up dependencies
mega setup

# Check if dependencies are installed
mega setup --check

Configuration

Mega CLI leverages Foundry's existing configuration system. For Foundry-specific settings, refer to the Foundry Book.

Project Structure

When you create a new project with mega init, it will generate a project with the following structure:

Full-Stack Project

my-mega-project/
├── foundry-app/            # Smart contract development
│   ├── lib/                # Dependencies including forge-std
│   ├── script/             # Deployment scripts
│   ├── src/                # Contract source files
│   ├── test/               # Contract test files
│   └── foundry.toml        # Foundry configuration
├── next-app/               # Frontend application
│   ├── public/             # Static assets
│   └── src/
│       ├── app/            # Next.js app router
│       │   └── gmega/      # Demo application routes
│       ├── components/     # Reusable components
│       ├── config/         # Application configuration
│       ├── constants/      # Constants and types
│       └── context/        # React context providers
└── README.md

Frontend-Only Project

my-mega-project/
├── public/                 # Static assets
├── src/
│   ├── app/                # Next.js app router
│   │   └── gmega/          # Demo application routes
│   ├── components/         # Reusable components
│   ├── config/             # Application configuration
│   ├── constants/          # Constants and types
│   └── context/            # React context providers
└── package.json

Foundry-Only Project

my-mega-project/
├── lib/                    # Dependencies including forge-std
├── script/                 # Deployment scripts
├── src/                    # Contract source files
├── test/                   # Contract test files
└── foundry.toml            # Foundry configuration

Examples

Deploying a Contract

# Compile your contracts
mega compile

# Deploy to Mega testnet
mega deploy foundry-app/src/GmegaCounter.sol:GmegaCounter --broadcast --testnet --account dev

Creating and Using Accounts

# Create a new account
mega account create
# > Enter a name for your wallet: myaccount

# Use this account to deploy a contract
mega deploy foundry-app/src/GmegaCounter.sol:GmegaCounter --broadcast

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published