Examples
This section provides practical examples and complete workflows to help you get the most out of Mega CLI.Smart Contract Development Workflow
This example shows a complete workflow for developing, testing, and deploying a smart contract to the Mega testnet.1. Initialize a Foundry Project
2. Create a Simple Contract
Create a file namedsrc/Counter.sol
:
3. Write a Test
Create a file namedtest/Counter.t.sol
:
4. Compile and Test
5. Deploy Locally
You can use the mega deploy command like so:6. Create an Account
7. Get Testnet Tokens
8. Deploy to Testnet
Full-Stack App Development Workflow
This example demonstrates how to create and run a full-stack application.1. Initialize a Full-Stack Project
2. Start the Development Environment
3. Deploy a Contract to the Local Chain
In a new terminal:4. Connect the Frontend to the Contract
Updatenext-app/src/constants/index.js
with your contract address:
5. Test the Application
After starting the development environment withmega dev
, you can:
- Visit
http://localhost:3000/gmega
in your browser - Connect your wallet
- Interact with the deployed contract