Skip to content
Merged
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
README.md
217 changes: 188 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,88 @@
# 🔥⚒️🎮 **Forge Token Crafting Game**
[![Live Demo](https://img.shields.io/badge/Live-Demo-blue)](https://forge-tokens.vercel.app)
![Foundry](https://img.shields.io/badge/Foundry-Tested-informational)
![Coverage](https://img.shields.io/badge/Coverage-100%25-brightgreen)

---
# 🔥⚒️ **Forge Token Crafting Game**

## **Game Overview**
---

**Forge** is a Web3 token crafting game where players mint, burn, and trade tokens to create rare items. Basic tokens can be minted directly, while forged tokens require burning combinations of basic tokens. The game includes a cooldown mechanism to prevent spamming.

> I built Forge to challenge myself with full-stack Web3 development: **Solidity** + **Foundry** for on-chain game logic, and a modern **Next.js** dApp that handles **real-time blockchain events**. The goal was to create a complete, production-style project touching frontend, backend, smart contracts, deployment, and testing.

---

## 🚀 Quick Start

##### 1. Try the Demo: [🌐 Live Demo](https://forge-tokens.vercel.app)
### 1. Try the Demo: [🌐 Live Demo](https://forge-tokens.vercel.app)

### 2. Get Testnet ETH: [Sepolia Faucet](https://sepolia-faucet.pk910.de/)

### 3. Connect your wallet to the DApp

### 4. Start Forging

- Mint basic tokens: IDs 0, 1, 2

- Burn + combine basic tokens: to craft tokens 3, 4, 5, 6

- Trade tokens: turn any token into a different basic token

---

## ✨ Main Features

- On-chain token crafting system (ERC-1155)
- Event-driven gameplay: real-time updates via WebSocket
- Cooldown-based minting for game balance
- Full Web3 integration (Wagmi + RainbowKit)
- Responsive dApp (desktop + mobile)
- 100% contract test coverage (Foundry)
- Deployed contracts on Sepolia
- Verified contracts on Etherscan

---

## 🎥 Demo Previews

##### 2. Get Testnet ETH: [Sepolia Faucet](https://sepolia-faucet.pk910.de/)
### 🖥️ Desktop Gameplay

##### 3. Connect your wallet to the DApp
#### **1. Minting Basic Tokens**

##### 4. Forge Tokens
![Minting Tokens](./assets/desktop-mint.01.gif)

###### - Mint Basic Tokens
#### **2. Trading Tokens**

- Start by minting basic tokens (0, 1, 2)
![Trading Tokens](./assets/desktop-trade.02.gif)

###### - Burn and Forge
#### **3. Forging Rare Tokens**

- Burn combinations of basic tokens to create forged tokens (3, 4, 5, 6).
![Forging Tokens](./assets/desktop-forge.03.gif)

###### - Trade Tokens
#### **4. Burning Tokens**

- Optimize your inventory by trading tokens.
![Burning Tokens](./assets/desktop-burn.04.gif)

---

## **Game Rules**
### 📱 Mobile Preview

### **1. Token Categories**
#### **Minting on Mobile**

![Mobile Mint](./assets/mobile-mint.gif)

---

## 📜 Game Rules

### 1. Token Categories

| Token IDs | Type | Minting Rule |
|-----------|-----------|---------------------------------------|
| 0, 1, 2 | Basic | Mint directly (1-minute cooldown). |
| 0, 1, 2 | Basic | Mint directly (15 seconds cooldown). |
| 3, 4, 5, 6| Forged | Burn specific basic tokens to mint. |

### **2. Minting Rules**
### 2. Minting Rules

- **Basic Tokens (0, 1, 2):**
- **Cooldown:** 15 seconds per user.
Expand All @@ -54,20 +95,16 @@
- **Token 5:** Burn 1x token 0 + 1x token 2.
- **Token 6:** Burn 1x token 0 + 1x token 1 + 1x token 2.

### **3. Burning & Trading**

- **Burning:** Only tokens 3-6 can be burned directly.
- **Trading:** Burn any token to mint tokens 0-2 (cannot trade a token for itself).
### 3. Burning & Trading Rules

### **Key Constraints**

- **Cooldown:** Applies only to minting tokens 0-2.
- **Single Mint:** Only 1 token per function call.
- **Ownership:** Only the Forge contract can mint/burn tokens.
- Tokens 3–6 can be burned directly
- Trading: burn any token to mint one of token 0, 1, or 2
- Cannot trade a token into itself
- Only the Forge contract can mint/burn tokens

---

## **Tech Stack**
## 🧰 Tech Stack

### Frontend

Expand Down Expand Up @@ -106,9 +143,131 @@
[0x8281b01D35A70BDc17D85c6df3d45B67745a5F9f](https://sepolia.etherscan.io/address/0x8281b01D35A70BDc17D85c6df3d45B67745a5F9f#code)
*(Verified on Etherscan)*

### **Testing**
---

## 🚀 Setup & Deployment

Below is everything needed to run, test, and deploy the Forge contracts and its frontend.

### Clone project

```bash
git clone git@github.com:SiegfriedBz/Forge-DApp.git
```

---

### 🔧 Backend Setup (Foundry)

All global deployment parameters
(e.g., `TOKEN_URI`, `MAX_TOKEN_ID`, `COOL_DOWN_DELAY`)
are located in:

```bash
be/script/Forge_Constants.sol
```

#### 1. Environment Variables (Backend)

Create a `.env` file in `/be`:

```bash
# Backend - Foundry
ALCHEMY_SEPOLIA_RPC_URL=
ETHERSCAN_API_KEY=
PRIVATE_KEY=
```

#### 2. Deploy Contracts to *Sepolia* Testnet (auto-verify)

```bash
# Backend - Foundry
cd be
# Deploy Forge & FToken contracts
forge script script/ForgeScript.s.sol \
--rpc-url $ALCHEMY_SEPOLIA_RPC_URL \
--broadcast \
--verify
```

This deploys:

- Forge.sol (core forging logic)
- FToken.sol (ERC1155 collection)

---

### 🖥️ Frontend Setup (Next.js)

#### 1. Environment Variables (Frontend)

Create a `.env` file in `/fe`:

```bash
# Frontend
NEXT_PUBLIC_ETH_SEPOLIA_ALCHEMY_HTTP_URL=
NEXT_PUBLIC_ETH_SEPOLIA_ALCHEMY_WS_URL= # For live onchain updates
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=
```

#### 2. Contract Addresses & ABIs

Update:
`/fe/app/_contracts/`
with the latest ABIs and deployed contract addresses from the backend deployment output.

#### 3. Install dependencies & run locally

```bash
# Frontend
cd fe
pnpm install
pnpm dev
```

---

### 🧪 Testing & Coverage (Smart Contracts)

All smart contracts were tested using Foundry with full branch, statement, and function coverage.

Run Full Test Suite locally:

```bash
cd be
forge test
```

Coverage Report:

```bash
cd be
forge coverage
```

<details>
<summary><strong>View Coverage Report (100%)</strong></summary>

| File | Lines | Statements | Branches | Funcs |
| ----------------------------- | ---------------- | ---------------- | ---------------- | ---------------- |
| **script/FTokenScript.s.sol** | 100% (6/6) | 100% (5/5) | 100% (0/0) | 100% (1/1) |
| **script/ForgeScript.s.sol** | 100% (6/6) | 100% (5/5) | 100% (0/0) | 100% (1/1) |
| **src/FToken.sol** | 100% (16/16) | 100% (11/11) | 100% (1/1) | 100% (7/7) |
| **src/Forge.sol** | 100% (67/67) | 100% (78/78) | 100% (18/18) | 100% (8/8) |
| **Total** | **100% (95/95)** | **100% (99/99)** | **100% (19/19)** | **100% (17/17)** |

</details>

---
🎯 Project Summary

Forge is an ERC1155 mint → forge → trade onchain game where players progressively transform base materials into higher-tier items.
Contracts enforce forging rules, cooldowns, and token evolution, while the frontend provides a smooth UX built with:

- **100% Coverage:** Both Solidity contracts (Forge + FToken) are tested with **Foundry**.
- Next.js 16
- Foundry + Solidity
- Wagmi + Viem
- Alchemy WebSockets for live on-chain events

---

Expand Down
Binary file added assets/desktop-burn.04.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/desktop-forge.03.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/desktop-mint.01.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/desktop-trade.02.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/mobile-mint.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions be/lib/openzeppelin-contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# <img src="logo.svg" alt="OpenZeppelin" height="40px">

[![Github Release](https://img.shields.io/github/v/tag/OpenZeppelin/openzeppelin-contracts.svg?filter=v*&sort=semver&label=github)](https://github.com/OpenZeppelin/openzeppelin-contracts/releases/latest)
[![NPM Package](https://img.shields.io/npm/v/@openzeppelin/contracts.svg)](https://www.npmjs.org/package/@openzeppelin/contracts)
[![Coverage Status](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts/graph/badge.svg)](https://codecov.io/gh/OpenZeppelin/openzeppelin-contracts)
[![GitPOAPs](https://public-api.gitpoap.io/v1/repo/OpenZeppelin/openzeppelin-contracts/badge)](https://www.gitpoap.io/gh/OpenZeppelin/openzeppelin-contracts)
[![Docs](https://img.shields.io/badge/docs-%F0%9F%93%84-yellow)](https://docs.openzeppelin.com/contracts)
[![Forum](https://img.shields.io/badge/forum-%F0%9F%92%AC-yellow)](https://forum.openzeppelin.com/)

**A library for secure smart contract development.** Build on a solid foundation of community-vetted code.

* Implementations of standards like [ERC20](https://docs.openzeppelin.com/contracts/erc20) and [ERC721](https://docs.openzeppelin.com/contracts/erc721).
* Flexible [role-based permissioning](https://docs.openzeppelin.com/contracts/access-control) scheme.
* Reusable [Solidity components](https://docs.openzeppelin.com/contracts/utilities) to build custom contracts and complex decentralized systems.

:mage: **Not sure how to get started?** Check out [Contracts Wizard](https://wizard.openzeppelin.com/) — an interactive smart contract generator.

> [!IMPORTANT]
> OpenZeppelin Contracts uses semantic versioning to communicate backwards compatibility of its API and storage layout. For upgradeable contracts, the storage layout of different major versions should be assumed incompatible, for example, it is unsafe to upgrade from 4.9.3 to 5.0.0. Learn more at [Backwards Compatibility](https://docs.openzeppelin.com/contracts/backwards-compatibility).

## Overview

### Release tags

We use NPM tags to clearly distinguish between audited and non-audited versions of our package:

| Tag | Purpose | Description |
| :--------- | :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **latest** | ✅ Audited releases | Stable, audited versions of the package. This is the **default** version installed when users run `npm install @openzeppelin/contracts`. |
| **dev** | 🧪 Final but not audited | Versions that are finalized and feature-complete but have **not yet been audited**. This version is fully tested, can be used in production and is covered by the bug bounty. |
| **next** | 🚧 Release candidates | Pre-release versions that are **not final**. Used for testing and validation before the version becomes a final `dev` or `latest` release. |

### Installation

#### Hardhat (npm)

```
$ npm install @openzeppelin/contracts
```
→ Installs the latest audited release (`latest`).

```
$ npm install @openzeppelin/contracts@dev
```
→ Installs the latest unaudited release (`dev`).

#### Foundry (git)

> [!WARNING]
> When installing via git, it is a common error to use the `master` branch. This is a development branch that should be avoided in favor of tagged releases. The release process involves security measures that the `master` branch does not guarantee.

> [!WARNING]
> Foundry installs the latest version initially, but subsequent `forge update` commands will use the `master` branch.

```
$ forge install OpenZeppelin/openzeppelin-contracts
```

Add `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/` in `remappings.txt`.

### Usage

Once installed, you can use the contracts in the library by importing them:

```solidity
pragma solidity ^0.8.20;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MyCollectible is ERC721 {
constructor() ERC721("MyCollectible", "MCO") {
}
}
```

_If you're new to smart contract development, head to [Developing Smart Contracts](https://docs.openzeppelin.com/learn/developing-smart-contracts) to learn about creating a new project and compiling your contracts._

To keep your system secure, you should **always** use the installed code as-is, and neither copy-paste it from online sources nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.

## Learn More

The guides in the [documentation site](https://docs.openzeppelin.com/contracts) will teach about different concepts, and how to use the related contracts that OpenZeppelin Contracts provides:

* [Access Control](https://docs.openzeppelin.com/contracts/access-control): decide who can perform each of the actions on your system.
* [Tokens](https://docs.openzeppelin.com/contracts/tokens): create tradeable assets or collectibles for popular ERC standards like ERC-20, ERC-721, ERC-1155, and ERC-6909.
* [Utilities](https://docs.openzeppelin.com/contracts/utilities): generic useful tools including non-overflowing math, signature verification, and trustless paying systems.

The [full API](https://docs.openzeppelin.com/contracts/api/token/ERC20) is also thoroughly documented, and serves as a great reference when developing your smart contract application. You can also ask for help or follow Contracts' development in the [community forum](https://forum.openzeppelin.com).

Finally, you may want to take a look at the [guides on our blog](https://blog.openzeppelin.com/), which cover several common use cases and good practices. The following articles provide great background reading, though please note that some of the referenced tools have changed, as the tooling in the ecosystem continues to rapidly evolve.

* [The Hitchhiker’s Guide to Smart Contracts in Ethereum](https://blog.openzeppelin.com/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05) will help you get an overview of the various tools available for smart contract development, and help you set up your environment.
* [A Gentle Introduction to Ethereum Programming, Part 1](https://blog.openzeppelin.com/a-gentle-introduction-to-ethereum-programming-part-1-783cc7796094) provides very useful information on an introductory level, including many basic concepts from the Ethereum platform.
* For a more in-depth dive, you may read the guide [Designing the Architecture for Your Ethereum Application](https://blog.openzeppelin.com/designing-the-architecture-for-your-ethereum-application-9cec086f8317), which discusses how to better structure your application and its relationship to the real world.

## Security

This project is maintained by [OpenZeppelin](https://openzeppelin.com) with the goal of providing a secure and reliable library of smart contract components for the ecosystem. We address security through risk management in various areas such as engineering and open source best practices, scoping and API design, multi-layered review processes, and incident response preparedness.

The [OpenZeppelin Contracts Security Center](https://contracts.openzeppelin.com/security) contains more details about the secure development process.

The security policy is detailed in [`SECURITY.md`](./SECURITY.md) as well, and specifies how you can report security vulnerabilities, which versions will receive security patches, and how to stay informed about them. We run a [bug bounty program on Immunefi](https://immunefi.com/bounty/openzeppelin) to reward the responsible disclosure of vulnerabilities.

The engineering guidelines we follow to promote project quality can be found in [`GUIDELINES.md`](./GUIDELINES.md).

Past audits can be found in [`audits/`](./audits).

Smart contracts are a nascent technology and carry a high level of technical risk and uncertainty. Although OpenZeppelin is well known for its security audits, using OpenZeppelin Contracts is not a substitute for a security audit.

OpenZeppelin Contracts is made available under the MIT License, which disclaims all warranties in relation to the project and which limits the liability of those that contribute and maintain the project, including OpenZeppelin. As set out further in the Terms, you acknowledge that you are solely responsible for any use of OpenZeppelin Contracts and you assume all risks associated with any such use.

## Contribute

OpenZeppelin Contracts exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guide](CONTRIBUTING.md)!

## License

OpenZeppelin Contracts is released under the [MIT License](LICENSE).

## Legal

Your use of this Project is governed by the terms found at www.openzeppelin.com/tos (the "Terms").
Loading