Examples
Practical examples and workflows using Mega CLI
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 named src/Counter.sol
:
3. Write a Test
Create a file named test/Counter.t.sol
:
4. Compile and Test
5. Deploy Locally
You can use the mega deploy command like so:
For more complex deployment scenarios, you can still create deployment scripts in the script/ directory, but for this example, we’ll use the direct deployment approach.
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
Update next-app/src/constants/index.js
with your contract address:
5. Test the Application
After starting the development environment with mega dev
, you can:
- Visit
http://localhost:3000/gmega
in your browser - Connect your wallet
- Interact with the deployed contract
Was this page helpful?