Can We Build a Time-Decaying P2P Currency Without Blockchain? A Serverless PoC Using MultipeerConnectivity & Face ID(Translated from Qiita's article )
---
title: "Can We Build a Time-Decaying P2P Currency Without Blockchain? A Serverless PoC Using MultipeerConnectivity & Face ID"
tags: Swift, SwiftUI, iOS, P2P, IndieDev
author: KouheiTakagi
slide: false
---
https://qiita.com/KouheiTakagi/items/aa8db0f299e31f6b2179
## Introduction
What happens if we implement a **"currency whose value evaporates over time"** using **only standard iOS / macOS frameworks (SwiftUI)—with zero blockchains and zero central servers?**
As a thought experiment and technical proof-of-concept (PoC), I built and open-sourced **"Dew"**, a peer-to-peer (P2P), time-decaying local currency protocol that springs forth every morning via biometric authentication and gradually disappears if hoarded.
🔗 **GitHub Repository:** [Kouhei-Takagi/Dew](https://github.com/Kouhei-Takagi/Dew)[cite: 2, 4]

### 💧 Three Core Features of Dew
1. **🌱 Proof of Humanity Minting:** Powered by `LocalAuthentication` (Face ID / Touch ID), proving the simple physical reality that "a flesh-and-blood human being is alive today" mints **+100.0 DEW** directly from your personal device without any central server.
2. **⏳ Continuous Exponential Time Decay:** Like morning dew evaporating as the sun rises, hoarded coins decay exponentially in real time based on elapsed time.
3. **📡 Zero-Server P2P Transfer:** Built on `MultipeerConnectivity`, nearby iPhones, iPads, and Macs automatically discover one another and exchange value directly over Bluetooth and P2P Wi-Fi—even in Airplane Mode with zero internet connection.
---
## 🌍 Philosophy & Background: Why "Dew"?
Let me briefly share the philosophy behind this architecture.
Our current economic trajectory—driven by **"Self-Expanding Capital × Centralized Currency × AI (the 24/365 worker)"**—is heading toward a structural dead end[cite: 2, 4, 12]. When sleepless, uncomplaining AI replaces human labor and capital compounds infinitely ($r > g$), wealth concentrates among a tiny fraction of winners. Worse still, because existing currency can be hoarded indefinitely, younger generations entering society late are forced into an unfair game of musical chairs where all the seats (assets and capital) are already taken, leaving them trapped in an exhausting rat race[cite: 7, 9, 12].
To directly invert these structural bugs—and to guarantee a fair starting line every single morning regardless of age or prior wealth—Dew is built on three pillars[cite: 4, 7, 12]:
| Element | Current Model | Next Style: **Dew** | Essence of the Shift |
| :--- | :--- | :--- | :--- |
| **Currency** | Expanding Capital (Interest & Hoarding) | **Time-Decay Coin** (Evaporating Value) | From *Monopoly* to *Circulation & Gifting* |
| **Network** | Centralized (Banks & Big Tech) | **Local P2P** (Autonomous Mesh) | From *Control* to *Direct Trust & Autonomy* |
| **Value Source** | AI (Infinite 24/365 Compute) | **Human Device** (Proof of Humanity) | From *Productivity* to *Human Existence Itself* |
### The "Dual Economy" of Stock and Flow: A Peaceful Bypass Surgery, Not a Revolution
Importantly, **Dew is not designed to overthrow or replace existing fiat currencies, governments, or macroeconomic systems**. Instead, it proposes a harmonious division of labor—a **Dual Economy (Two-Tier Currency System)**[cite: 4, 9, 11]:
* **The Stock Economy (The Arteries = Fiat Currency & AI):** Long-term assets, real estate, power grids, data centers, and global logistics continue to be managed and maintained by existing fiat currencies, states, and AI[cite: 4, 8, 9, 11].
* **The Flow Economy (The Capillaries = Time-Decay Coin & Humans):** Daily food, local services, skill-sharing among young people, caregiving, and everyday expressions of gratitude are circulated locally via a time-decaying currency[cite: 4, 7, 8, 9].
In regions experiencing deflation or intense labor competition, goods, human skills, and time are abundant, yet people struggle simply because fiat currency is scarce or hoarded. By introducing a currency that evaporates over time, speculation and capital hoarding become mathematically impossible—acting as a natural "poison" to predatory algorithms and speculators while leaving existing state and capital assets untouched[cite: 4, 11]. Rather than a disruptive revolution, Dew acts as a **peaceful bypass surgery**: keeping local communities vibrant, supporting the dignity of young people, and maintaining the utilization of social infrastructure so that both the "Stock" and "Flow" layers can prosper together[cite: 7, 9, 11].
---
## 📂 System Architecture
Dew uses zero external libraries and zero backend servers. The entire protocol is implemented in **just 5 minimal `.swift` files**.
```text
Dew/
├── MyApp.swift # App entry point
├── ContentView.swift # Glassmorphism UI & real-time decay visualizer
├── DewWallet.swift # Exponential time-decay calculation engine
├── BiometricMinter.swift # Face ID / Touch ID Proof-of-Humanity minter
└── DewP2PManager.swift # Serverless P2P discovery & payload transfer manager
```
## 🛠 Core Technical Implementation
How can we create a working time-decaying P2P currency without heavy blockchain consensus algorithms? Here is how the three core modules work.
### 1. Serverless Continuous Exponential Decay Engine (`DewWallet.swift`)
If we relied on a central server's cron job to periodically deduct balances, it would require ongoing server costs and constant internet connectivity.
Instead, Dew calculates the current balance $B(t)$ purely on the client side in real time, using the elapsed time $t$ since the last state update and a half-life constant $T_{1/2}$:
$$B(t) = B_0 \times \left(\frac{1}{2}\right)^{\frac{t}{T_{1/2}}}$$
With this formula, whether the app is closed or the device is completely offline, value evaporates purely mathematically as the clock ticks.
- **Real Mode:** Half-life $T_{1/2} = 86,400\text{ seconds}$ (24 hours)
- **Demo Mode:** Half-life $T_{1/2} = 180\text{ seconds}$ (3 minutes)
For easy testing, the UI includes a one-tap toggle between "Demo Mode (3-min half-life)" and "Real Mode (24-hr half-life)". In `ContentView.swift`, the `.monospacedDigit()` modifier renders the balance smoothly counting down to 4 decimal places as it evaporates before your eyes.
```swift
// Exponential decay calculation in DewWallet.swift
func currentBalance(at now: Date = Date()) -> Double {
let elapsed = now.timeIntervalSince(lastUpdated)
guard elapsed > 0, baseBalance > 0 else { return baseBalance }
return baseBalance * pow(0.5, elapsed / halfLife)
}
```
### 2. Proof of Humanity via Face ID (`BiometricMinter.swift`)
No matter how advanced AI becomes, it can never replicate the physical reality of a finite, living human being experiencing a 24-hour day.
Dew defines a personal smartphone as a **"Human Device" (minting node)**. By passing Apple's `LocalAuthentication` (Face ID / Touch ID), any person can locally mint **+100.0 DEW** once per day.
- Without waiting for central approval or competing in a zero-sum labor market, currency springs directly from your device as a proof of living another day.
- Because hoarding it means losing half of it by tomorrow, the most rational strategy is to use it or gift it to someone nearby today. Whether you are a 20-year-old student just starting out or a billionaire, everyone wakes up to the exact same +100.0 DEW each morning.
### 3. Zero-Server P2P Mesh Communication (`DewP2PManager.swift`)
To eliminate platform rent-seeking and ensure complete local resilience, the networking layer uses Apple's native `MultipeerConnectivity` framework.
- By specifying `serviceType: "dew-p2p"` and running `MCNearbyServiceAdvertiser` and `MCNearbyServiceBrowser` simultaneously, nearby devices automatically discover and connect to one another over Bluetooth and P2P Wi-Fi.
- Even in environments with zero routers or internet access (such as Airplane Mode with Wi-Fi/Bluetooth enabled, rural areas, or during natural disasters), you can exchange DEW directly with the person standing right in front of you.
---
## 🚀 Build & Run Instructions (Try It Yourself)
The codebase is simple enough to build and test on real devices in just a few minutes.
1. Create a new **iOS App** or **Multiplatform App** project (SwiftUI) in Xcode 15 or later.
2. Drag and drop the 5 `.swift` files from the repository into your project.
3. Add the following three keys to your target's `Info.plist` (Target > Info > Custom iOS Target Properties):
| Key | Type | Value |
| :--- | :--- | :--- |
| `NSFaceIDUsageDescription` | String | Used to verify Proof of Humanity and mint your daily Dew. |
| `NSLocalNetworkUsageDescription` | String | Used to discover nearby devices and transfer Dew directly via P2P. |
| `NSBonjourServices` | Array | Item 0: `_dew-p2p._tcp` / Item 1: `_dew-p2p._udp` |
> 💡 **Important Pitfall:** Since iOS 14, `MultipeerConnectivity` requires both `NSLocalNetworkUsageDescription` and `NSBonjourServices` to be explicitly declared in `Info.plist`. Without both, iOS will silently block local P2P communication without even showing the permission prompt.
4. Build and run the app on two or more devices (e.g., an iPhone and an iPad, or a Mac and the Simulator) to experience real-time value evaporation and instant P2P transfers.
---
## 🔭 Future Roadmap: Synchronizing with Human Biorhythms
While the current PoC uses a "daily mint / 24-hour half-life" cycle, future iterations of the protocol aim to synchronize even more naturally with human biology and local community rhythms:
- **The "Weekly Mint × 2-Week Decay" Biorhythm:**
A daily cycle can feel slightly rushed, while a monthly cycle feels too mechanical. Expanding to a "7-day issuance × 14-day smooth decay" fits the natural human rhythm of working on weekdays and resting or visiting local markets on weekends—even leaving room to recover if you catch a cold for a few days.
- **Minting Triggered by "Waking Up from Restorative Sleep":**
If everyone receives coins simultaneously at midnight on Monday, it creates artificial boom-and-bust cycles and panic spending. By triggering issuance upon **"waking up from a full sleep (e.g., 5+ hours)"**—a biological cycle that 24/365 AI bots do not possess—and staggering issuance days across individuals, communities maintain a smooth, natural gradient between those looking to spend/gift DEW and those looking to earn it every day.
---
## ⚠ Disclaimer & License
The code and application in this repository are a **purely conceptual, educational, and technical Proof-of-Concept (PoC) prototype** designed to explore tokenomics, social philosophy, and local P2P communication.
The "DEW" units displayed inside the app have zero monetary value, cannot be exchanged for fiat currencies or crypto-assets, and do not constitute a financial instrument, currency, security, or prepaid payment instrument under any jurisdiction.
This project is released as open source under the **Apache License 2.0**. Its Patent Retaliation Clause protects the concept from monopolization, allowing anyone, anywhere, to freely modify, port, and experiment with autonomous community loops.
🔗 **GitHub:** [https://github.com/Kouhei-Takagi/Dew](https://github.com/Kouhei-Takagi/Dew)
---
## Update (October 29, 2026): The Universal AI Prompt
Below is the exact prompt given to the AI coding agent (**Antigravity**) to generate the Dew MVP.
Because a well-structured prompt acts as "universal source code," you can feed this prompt into your favorite AI coding assistant to instantly reproduce this app—or ask your AI to port it to **Android (Kotlin / Nearby Connections API)** or Web apps to fit your local community's devices.
```text
Please implement the MVP (Minimum Viable Product) for Project "Dew" using SwiftUI.
"Dew" is a serverless (P2P) local currency app minted once a day via biometric authentication (Human Device), whose value gradually evaporates over time (Time-Decay Coin).
It should allow iPhones, iPads, and Macs (Apple Silicon) to send and receive coins directly without an internet connection.
Following the 4 core requirements and file structure below, please generate modern, warning-free Swift code (targeting Swift 5.9+ / iOS 17+ / macOS 14+).
## 1. Core Requirements & Specifications
1. **Time-Decay Logic (`DewWallet.swift`)**
- Manage the balance not as a static number, but using `baseBalance: Double` (balance at last update) and `lastUpdated: Date` (timestamp of last update), persisted via `UserDefaults`.
- Calculate `currentBalance` in real time using elapsed time `t` and `halfLife` via exponential decay: `baseBalance * pow(0.5, t / halfLife)`.
- **Important (Demo Feature)**: To visually test the sensation of "morning dew evaporating," provide a one-tap toggle between "Demo Mode (half-life: 180s = 3 mins)" and "Real Mode (half-life: 86,400s = 24 hours)". Render the balance counting down in real time to 4 decimal places (e.g., `99.8421 DEW`) using `TimelineView(.animation)` or a 0.1s `Timer`.
2. **Proof of Humanity Minting (`BiometricMinter.swift`)**
- Use the `LocalAuthentication` framework.
- Tapping the "Morning Mint (100 DEW)" button requests Face ID / Touch ID (or passcode) authentication. Upon success, add `+100.0 DEW` to the current decayed balance and update `lastUpdated` to the current timestamp.
- (Include a debug button to reset the once-per-day limit for prototype testing.)
3. **Direct P2P Communication (`DewP2PManager.swift`)**
- Use the `MultipeerConnectivity` framework (`serviceType = "dew-p2p"`).
- Automatically start `MCNearbyServiceAdvertiser` and `MCNearbyServiceBrowser` on app launch to auto-discover and connect to nearby iPhones, iPads, and Macs.
- Encode the transfer payload `DewTransferPayload: Codable` (sender device name, `amount: Double`, timestamp, UUID) as JSON and send it to the selected peer (or all connected peers).
- The sender immediately deducts `amount` from their balance, while the receiver adds `amount` to their balance and displays an animated notification: "💧 Received X DEW from [Device]!".
4. **UI Design (`ContentView.swift`)**
- A clean, translucent glassmorphism UI with a cyan/emerald gradient inspired by morning dew.
- Top: Real-time decaying balance (displayed large with `.monospacedDigit()`) and a toggle switch for evaporation speed (Demo 3m / Real 24h).
- Center: "🌱 Proof of Humanity (Mint 100 DEW)" button (biometric trigger).
- Bottom: List of discovered nearby P2P devices and one-tap transfer buttons ("Send 10 DEW", "Send 50 DEW").
## 2. Required Configuration (`Info.plist` / Entitlements)
Ensure `MultipeerConnectivity` and `Face ID` run on physical devices without crashing by providing instructions for these `Info.plist` keys:
- `NSFaceIDUsageDescription`: "Used to verify Proof of Humanity and mint your daily Dew."
- `NSLocalNetworkUsageDescription`: "Used to discover nearby devices and transfer Dew directly via P2P."
- `NSBonjourServices`: `["_dew-p2p._tcp", "_dew-p2p._udp"]`
Please create the file structure and implement all code files.
```
#### 🤝 Acknowledgments
The philosophical foundation of Project "Dew" (such as the Dual Economy model and synchronization with human biorhythms) and its architectural requirements were conceptualized and articulated through brainstorming sessions with **Google Gemini**, and the code was implemented from that blueprint via **Antigravity**.
Co-creating a protocol for the human sphere in the age of AI by brainstorming with AI itself, and releasing it into the open-source sea—I extend my gratitude to the AI collaborators that explored this experimental journey with me.