From 5242fdcbce0dbe617a9cb81666ec9c850975283a Mon Sep 17 00:00:00 2001 From: Phantagyro <1phantagyro@gmail.com> Date: Sun, 27 Jul 2025 02:46:53 +0100 Subject: [PATCH] Add Foundry Counter tutorial for Monad testnet --- tutorials/foundry-counter/.env.example | 3 + tutorials/foundry-counter/README.md | 117 ++++++++++++++++++ tutorials/foundry-counter/script/Deploy.s.sol | 14 +++ tutorials/foundry-counter/src/Counter.sol | 11 ++ 4 files changed, 145 insertions(+) create mode 100644 tutorials/foundry-counter/.env.example create mode 100644 tutorials/foundry-counter/README.md create mode 100644 tutorials/foundry-counter/script/Deploy.s.sol create mode 100644 tutorials/foundry-counter/src/Counter.sol diff --git a/tutorials/foundry-counter/.env.example b/tutorials/foundry-counter/.env.example new file mode 100644 index 0000000..9d84112 --- /dev/null +++ b/tutorials/foundry-counter/.env.example @@ -0,0 +1,3 @@ +PRIVATE_KEY=your_wallet_private_key +RPC_URL=https://rpc.testnet.monad.xyz/ + diff --git a/tutorials/foundry-counter/README.md b/tutorials/foundry-counter/README.md new file mode 100644 index 0000000..3fa6d19 --- /dev/null +++ b/tutorials/foundry-counter/README.md @@ -0,0 +1,117 @@ +Here is the **`README.md`** content exactly as provided earlier, with **no rephrasing**: + +--- + +````markdown +# 🧪 Deploying a Minimal Counter Contract on Monad Testnet (Using Foundry) + +This tutorial walks you through deploying a simple `Counter.sol` contract to the Monad Testnet using Foundry. + +--- + +## 🛠 Prerequisites + +- [Foundry](https://book.getfoundry.sh/getting-started/installation) +- A funded wallet on Monad Testnet +- [RPC URL](https://rpc.testnet.monad.xyz/) +- A `.env` file with your wallet private key + +--- + +## 🧾 Setup + +Clone this repo or copy this folder structure: + +```bash +git clone https://github.com/monad-developers/foundry-monad +cd foundry-monad +```` + +Install dependencies: + +```bash +forge install +``` + +Create a `.env` file: + +```bash +cp .env.example .env +``` + +Edit `.env` with your private key and Monad RPC: + +```env +PRIVATE_KEY=your_private_key +RPC_URL=https://rpc.testnet.monad.xyz/ +``` + +--- + +## 🧱 Contract: `Counter.sol` + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +contract Counter { + uint256 public count; + + function increment() public { + count++; + } +} +``` + +--- + +## 🚀 Deployment Script + +Create `script/Deploy.s.sol`: + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "../src/Counter.sol"; + +contract Deploy is Script { + function run() external { + vm.startBroadcast(); + new Counter(); + vm.stopBroadcast(); + } +} +``` + +--- + +## ▶️ Deploying to Monad + +```bash +forge script script/Deploy.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast --verify +``` + +--- + +## ✅ Verifying Deployment + +If successful, you’ll see the deployed contract address in the terminal. + +You can interact with the contract using Foundry or a Monad explorer. + +--- + +## 🧠 Why This Matters + +* This is the **simplest Monad-compatible dApp** using Foundry. +* Fully testnet-compatible. +* Sets the foundation for more complex tutorials. + +--- + +## 🙌 Credits + +Feel free to fork, improve, or reference this for your own dApps! + diff --git a/tutorials/foundry-counter/script/Deploy.s.sol b/tutorials/foundry-counter/script/Deploy.s.sol new file mode 100644 index 0000000..5c09cbd --- /dev/null +++ b/tutorials/foundry-counter/script/Deploy.s.sol @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +import "forge-std/Script.sol"; +import "../src/Counter.sol"; + +contract Deploy is Script { + function run() external { + vm.startBroadcast(); + new Counter(); + vm.stopBroadcast(); + } +} + diff --git a/tutorials/foundry-counter/src/Counter.sol b/tutorials/foundry-counter/src/Counter.sol new file mode 100644 index 0000000..b327642 --- /dev/null +++ b/tutorials/foundry-counter/src/Counter.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.20; + +contract Counter { + uint256 public count; + + function increment() public { + count++; + } +} +