Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tutorials/foundry-counter/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRIVATE_KEY=your_wallet_private_key
RPC_URL=https://rpc.testnet.monad.xyz/

117 changes: 117 additions & 0 deletions tutorials/foundry-counter/README.md
Original file line number Diff line number Diff line change
@@ -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!

14 changes: 14 additions & 0 deletions tutorials/foundry-counter/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -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();
}
}

11 changes: 11 additions & 0 deletions tutorials/foundry-counter/src/Counter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Counter {
uint256 public count;

function increment() public {
count++;
}
}