Skip to content

Commit cf48be1

Browse files
committed
Merge upstream/main
Made-with: Cursor
2 parents 8c88b3d + 57c14d0 commit cf48be1

8 files changed

Lines changed: 305 additions & 13 deletions

File tree

website/docs/working-group/sessions/q2-2026/14-sdk-repo-walkthrough/recordings/readme.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,32 @@ sidebar_label: Recordings
44
slug: /working-group/q2-2026/sessions/14-sdk-repo-walkthrough/recordings
55
---
66

7-
# Session 14: Repository Walkthrough: Offchain and SDK building - Recordings
7+
# Session Recordings
88

9-
Recordings for the Offchain and SDK building walkthrough session.
9+
## Recording 1 (2026/04/16)
1010

11-
## Session 1
11+
🎥 **Repository Walkthrough: Offchain and SDK building**
1212

13-
*(Link to recording will be added here after the session)*
13+
<iframe
14+
src="https://www.youtube.com/embed/263p0foWkec"
15+
title="Session 14: Repository Walkthrough: Offchain and SDK building"
16+
width="100%"
17+
height="480"
18+
allow="autoplay"
19+
allowfullscreen
20+
style={{border: 0, borderRadius: '12px', boxShadow: '0 16px 40px rgba(1, 40, 170, 0.18)'}}
21+
/>
22+
23+
- **Status**: Recording available above.
24+
- **Highlights**:
25+
- Recap of the onchain Payment Subscription Smart Contract architecture (Account, Service, Payment).
26+
- Introduction to the offchain SDK codebase structure.
27+
- Transaction building with Lucid Evolution.
28+
- Endpoints walkthrough (e.g., `createService`, `updateService`).
29+
- Using `plutus.json` blueprint to get validators and endpoints.
30+
- Brief look at the Effect library in TypeScript development.
31+
- Writing tests for SDK endpoints to ensure reliability.
32+
- Discussion on the value of wrapping smart contracts with SDKs to lower entry barriers.
1433

1534
---
1635

website/docs/working-group/sessions/q2-2026/14-sdk-repo-walkthrough/session-notes/readme.md

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,65 @@ sidebar_label: Session Notes
44
slug: /working-group/q2-2026/sessions/14-sdk-repo-walkthrough/session-notes
55
---
66

7-
# Session 14: Repository Walkthrough: Offchain and SDK building - Notes
7+
# Repository Walkthrough: Offchain and SDK building
88

9-
Notes and resources exploring the offchain architecture of a production smart contract and SDK integration.
9+
## Introduction
1010

11-
## Overview
11+
This session is a continuation of the Q4 2025 walkthrough, shifting focus from the onchain code to the **offchain integration and SDK building**. We explore how to interact with the Payment Subscription Smart Contract built by Anastasia Labs, how to structure an SDK, and how to build transactions to interact with Cardano smart contracts using Lucid Evolution.
1212

13-
In this session, we explored the Cardano SDK ecosystem, repositories, and architecture.
13+
## Recap: The Smart Contract Architecture
1414

15-
## Additional Resources
15+
Before diving into the offchain code, we briefly recapped the three main validators of the contract:
16+
1. **Account Validator**: Acts as authentication. Uses CIP-68 standards to mint a paired reference token (sent to the contract) and user token (sent to the user's wallet).
17+
2. **Service Validator**: Used by merchants to define subscription services (e.g., Netflix-like plans) with specific fees and intervals.
18+
3. **Payment Validator**: Handles linear vesting, locking funds, and allowing merchants to withdraw fees periodically while letting users cancel or extend subscriptions.
1619

17-
- *(Links and resources will be added here after the session)*
20+
## The Offchain SDK Structure
21+
22+
A well-structured SDK is critical to lower the barrier to entry for Cardano developers. The project is organized into clear directories:
23+
- **`docs/`**: API endpoints documentation (in partnership with Maestro).
24+
- **`src/`**: The main source code.
25+
- **`core/`**: Contains helper functions and compiled contract blueprints (`plutus.json`).
26+
- **`endpoints/`**: Contains the transaction building logic for each contract action (e.g., `createService`, `updateService`).
27+
- **`examples/`**: Code snippets demonstrating how a third-party developer can use the SDK.
28+
29+
## Transaction Building Walkthrough
30+
31+
Using **Lucid Evolution** (though MashJS or others are viable), we walked through the `createService` endpoint to understand transaction building:
32+
33+
### 1. Extracting the Validator
34+
The `plutus.json` blueprint is parsed to extract the specific validator needed. Helper functions abstract this process to quickly get the required endpoints and policy IDs.
35+
36+
### 2. Collecting UTXOs and Minting
37+
The user's wallet is connected to select the necessary UTXOs. For creating a service:
38+
- The SDK mints two NFTs (Service Reference NFT and Service NFT) adhering to the CIP-68 standard.
39+
- The reference NFT is sent to the smart contract, and the user NFT goes to the merchant's wallet.
40+
41+
### 3. Configuring the Datum
42+
The SDK wraps all required parameters (e.g., service fee, interval length, penalty fee) into a `Config` object. This config is then formatted to match the exact `Datum` structure expected by the onchain code.
43+
44+
### 4. Building the Transaction
45+
```typescript
46+
lucid.newTx()
47+
.collectFrom(...)
48+
.mintAssets(...)
49+
.payToAddress(merchantAddress, ...)
50+
.payToContract(contractAddress, { inline: datum }, ...)
51+
.attachMintingPolicy(...)
52+
.complete()
53+
```
54+
*Note: The codebase utilizes the **Effect Library** in TypeScript (often seen via the `yield*` and `Effect.gen` syntax) to enforce robust type-safety, error handling, and standard execution flows.*
55+
56+
## Testing the SDK
57+
58+
Testing offchain code is just as important as the onchain code. The repository contains extensive tests:
59+
- Tests populate dummy configurations (simulating what a user would input).
60+
- Tests run the endpoint logic to ensure transactions build correctly.
61+
- Helper functions sign and submit these test transactions to ensure end-to-end reliability.
62+
63+
## Key Takeaways
64+
- **SDKs Drive Adoption**: Wrapping complex smart contracts into clean, well-documented SDKs is one of the biggest opportunities in the Cardano ecosystem. It allows frontend developers to build without needing to write or understand Plutus.
65+
- **Blueprint Alignment**: The offchain code's main job is exactly mirroring the constraints, datums, and redeemers defined in the onchain design specification.
1866

1967
---
2068

website/docs/working-group/sessions/q2-2026/14-sdk-repo-walkthrough/session-resources/readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ Resources exploring the offchain architecture of a production smart contract and
1010

1111
## Additional Resources
1212

13-
- *(Links and resources will be added here after the session)*
13+
- **Payment Subscription Smart Contract (Onchain)**: [Anastasia-Labs/payment-subscription](https://github.com/Anastasia-Labs/payment-subscription)
14+
- **Payment Subscription SDK (Offchain)**: [Anastasia-Labs/payment-subscription-offchain](https://github.com/Anastasia-Labs/payment-subscription-offchain)
15+
- **Lucid Evolution SDK**: [Anastasia-Labs/lucid-evolution](https://github.com/Anastasia-Labs/lucid-evolution)
16+
- **CIP-68 Standard**: [Datum Metadata Standard](https://cips.cardano.org/cip/CIP-0068)
17+
- **Effect TypeScript Library**: [Effect Documentation](https://effect.website/)
1418

1519
---
1620

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Session 15: dApp Architecture: From Wallet to Backend",
3+
"position": 15
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: "Session 15: dApp Architecture: From Wallet to Backend - Recordings"
3+
sidebar_label: Recordings
4+
slug: /working-group/q2-2026/sessions/15-dapp-architecture-demo/recordings
5+
---
6+
7+
# Session 15: dApp Architecture: From Wallet to Backend - Recordings
8+
9+
Recordings for the dApp Architecture session.
10+
11+
## Session 1
12+
13+
<iframe
14+
width="100%"
15+
height="400"
16+
src="https://www.youtube.com/embed/D_8JOuWFHfY"
17+
title="Session 15: dApp Architecture: From Wallet to Backend"
18+
frameborder="0"
19+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
20+
allowfullscreen
21+
></iframe>
22+
23+
---
24+
25+
*This recording belongs to the Q2 2026 Developer Experience Working Group.*
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: "Session 15: dApp Architecture: From Wallet to Backend - Notes"
3+
sidebar_label: Session Notes
4+
slug: /working-group/q2-2026/sessions/15-dapp-architecture-demo/session-notes
5+
---
6+
7+
# Session 15: dApp Architecture: From Wallet to Backend - Notes
8+
9+
Notes and architectural breakdown for building full-stack applications on Cardano using Mesh SDK and Blockfrost.
10+
11+
## Overview
12+
Building on Cardano requires a different mental model than traditional "server-centric" applications. In a dApp, the blockchain is the **immutable source of truth**, while the frontend, wallet, and backend act as specialized interfaces to that truth.
13+
14+
---
15+
16+
## 🏗 Sequence Diagram: The Full Flow
17+
18+
The following diagram illustrates the interaction between the four layers during a typical payment-to-mint lifecycle.
19+
20+
```mermaid
21+
sequenceDiagram
22+
participant U as User / Wallet
23+
participant F as Frontend (Next.js)
24+
participant B as Backend (API)
25+
participant L as Blockchain (Cardano)
26+
participant BF as Blockfrost API
27+
28+
U->>F: 1. Click "Send Payment"
29+
F->>U: 2. Request Signature (CIP-30)
30+
U->>U: 3. User Approves / Signs
31+
U->>L: 4. Submit Tx to Node
32+
U->>F: 5. Return TxHash
33+
F->>B: 6. Register TxHash
34+
loop Every 10s
35+
B->>BF: 7. Get Tx Status & UTxOs
36+
BF->>B: 8. Return Confirmation Depth
37+
end
38+
Note over B: 9. Payment Verified (2+ Blocks)
39+
B->>B: 10. Build Mint Tx (Server Wallet)
40+
B->>L: 11. Submit Mint Tx
41+
L->>U: 12. Token Arrives in Wallet
42+
```
43+
44+
---
45+
46+
## 🧩 Deep Dive: The 4 Layers
47+
48+
### 1. User Wallet (The Signing Authority)
49+
The wallet's primary job is **Key Management**. The dApp *never* sees the user's private key.
50+
- **Protocol**: [CIP-30](https://cips.cardano.org/cips/cip30/) defines how the browser talks to the wallet.
51+
- **UX**: Whenever a dApp wants to move funds, the wallet pops up a "Confirm" dialog. This is the ultimate security barrier.
52+
53+
### 2. Frontend (The Orchestrator)
54+
The frontend uses the [Mesh SDK](https://meshjs.dev) to build transactions.
55+
- **Transaction Building**: The SDK gathers UTxOs from the wallet, adds outputs, and calculates fees.
56+
- **State Management**: The frontend must handle the "Waiting" UX, keeping the user informed while the blockchain confirms the transaction.
57+
58+
### 3. Backend (The Verification Engine)
59+
The backend's role is **Trustless Verification**. It must never trust the frontend's claim that "I paid".
60+
- **Verification Logic**: The backend queries Blockfrost for the `txHash` and inspects the **UTxO Outputs**.
61+
- **The Checklist**:
62+
1. Does the transaction exist on-chain?
63+
2. Does it have enough confirmations (e.g., 2 for demo, 15+ for production)?
64+
3. Is there an output to our **App Wallet Address**?
65+
4. Does that output contain the **correct ADA amount**?
66+
67+
### 4. Blockchain (The Source of Truth)
68+
The Cardano network (Ouroboros) provides the settlement layer.
69+
- **Mempool**: Where transactions live before being included in a block.
70+
- **Propagation**: The time it takes for a transaction to spread across nodes (usually a few seconds).
71+
- **Finality**: As more blocks are added on top of a transaction, it becomes mathematically impossible to reverse.
72+
73+
---
74+
75+
## 🔍 Code Spotlight: Verification Logic
76+
77+
The heart of this architecture lies in how the backend confirms a payment without trusting the user's claimed transaction state.
78+
79+
### 1. Polling via Blockfrost (poll-status.ts)
80+
The frontend triggers a polling loop every 10 seconds. The backend then performs a "live" check on the blockchain:
81+
82+
```typescript
83+
// pages/api/poll-status.ts snippet
84+
const { confirmed, confirmations, amountLovelace } = await verifyPayment(
85+
txHash,
86+
APP_WALLET_ADDRESS
87+
);
88+
89+
if (!confirmed) {
90+
// If not on-chain or not enough confirmations, keep waiting
91+
const newStatus = confirmations > 0 ? "CONFIRMING" : "PENDING";
92+
// ... update local record and return status
93+
}
94+
```
95+
96+
### 2. Identifying the Payment (blockfrost.ts)
97+
Verification isn't just about the transaction *existing*; it's about checking the **UTxO outputs** to ensure the funds reached their destination.
98+
99+
```typescript
100+
// lib/blockfrost.ts logic
101+
// 1. Get all outputs for the transaction
102+
const utxos = await getTxUTxOs(txHash);
103+
104+
// 2. Find the specific output directed to our App Wallet
105+
const paymentOutput = utxos.outputs.find(
106+
(output) => output.address === appWalletAddress
107+
);
108+
109+
// 3. Compare the sent ADA (lovelace) against the required price
110+
const sentLovelace = paymentOutput?.amount.find(a => a.unit === "lovelace")?.quantity;
111+
if (BigInt(sentLovelace) < BigInt(REQUIRED_LOVELACE)) {
112+
throw new Error("Insufficient payment amount");
113+
}
114+
```
115+
116+
---
117+
118+
## 🛡 Security Best Practices
119+
120+
> [!CAUTION]
121+
> **Server Wallet Security**: In this demo, the server wallet mnemonic is stored in an environment variable. In production, use a dedicated signing service, HSM (Hardware Security Module), or a vault like HashiCorp Vault.
122+
123+
* **API Key Safety**: Never expose your `BLOCKFROST_PROJECT_ID` in the frontend code. Keep it strictly on the server-side (`.env`).
124+
* **Input Validation**: Sanitize and validate every `txHash` received from the frontend to prevent injection or spam.
125+
* **Rate Limiting**: Implement rate limiting on your API routes to prevent users from flooding the polling engine.
126+
127+
---
128+
129+
## 🛰 Indexing & Event Listeners (Production Scale)
130+
131+
While polling Blockfrost is excellent for smaller dApps and demos, production systems require higher throughput and lower latency. This is achieved by shifting from a **Pull** mechanism (polling) to a **Push** mechanism (event-driven).
132+
133+
### 1. The Case for Indexers
134+
Standard nodes provide raw chain data, but they aren't optimized for complex queries (e.g., "Find all NFTs owned by this address"). Indexers consume raw chain data and transform it into a searchable database.
135+
136+
### 2. Event Listeners (Oura)
137+
[Oura](https://github.com/txpipe/oura) is a popular tool for "tailing" the Cardano blockchain. It listens for events in real-time and routes them to different sinks (Elasticsearch, Kafka, Webhooks).
138+
- **Use Case**: Real-time notifications ("Your payment was just received!") before the transaction is even fully confirmed.
139+
- **Benefit**: Extremely low latency compared to polling.
140+
141+
### 3. Purpose-Built Indexers
142+
* **[Kupo](https://github.com/Cardano-Solutions/kupo)**: A lightweight indexer focused on the UTxO model. Ideal for dApps that need to quickly find available funds or specific script outputs.
143+
* **[Ogmios](https://ogmios.dev/)**: A bridge that provides a JSON-RPC interface to the Cardano node, making it easier for web-based tools to query the node directly.
144+
* **[Cardano DB Sync](https://github.com/intersectmbo/cardano-db-sync)**: The "heavyweight" champion. It mirrors the entire chain into a PostgreSQL database. Essential for analytics platforms or explorers.
145+
* **[Yaci Store](https://store.yaci.xyz/)**: A developer-focused indexing solution providing high-level APIs for blockchain data, designed for rapid application development.
146+
147+
### 4. Hybrid Architecture
148+
In many production dApps, companies use a hybrid approach:
149+
- **Blockfrost** for quick features and mobile compatibility.
150+
- **Oura** for real-time UI updates (Optimistic UI).
151+
- **Kupo/Ogmios** for complex transaction building and backend verification.
152+
153+
---
154+
155+
*These notes belong to the Q2 2026 Developer Experience Working Group.*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: "Session 15: dApp Architecture: From Wallet to Backend - Resources"
3+
sidebar_label: Session Resources
4+
slug: /working-group/q2-2026/sessions/15-dapp-architecture-demo/session-resources
5+
---
6+
7+
# Session 15: dApp Architecture: From Wallet to Backend - Resources
8+
9+
Curated resources and tools for building full-stack dApps on Cardano.
10+
11+
## Official Tools & SDKs
12+
13+
* **[Mesh SDK](https://meshjs.dev)**: The primary SDK used in this demo for transaction building and wallet integration.
14+
* **[Blockfrost.io](https://blockfrost.io)**: The API provider used for blockchain polling and data retrieval.
15+
* **[Cardano Developer Portal](https://developers.cardano.org)**: The central hub for all technical documentation.
16+
17+
## Demo Project
18+
19+
* **[Educational dApp Demo](file:///Users/tyty/Desktop/Demos/cardano-dapp-demo)**: The source code for the architecture demonstrated in this session.
20+
21+
## Further Reading
22+
23+
* **[CIP-30 (Wallet Bridge)](https://cips.cardano.org/cips/cip30/)**: The standard for how dApps talk to wallets.
24+
* **[CIP-25 (NFT Metadata)](https://cips.cardano.org/cips/cip25/)**: The standard for on-chain asset metadata used in our minting flow.
25+
26+
---
27+
28+
*These resources belong to the Q2 2026 Developer Experience Working Group.*

website/docs/working-group/sessions/q2-2026/index.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ The Developer Experience (DevEx) Working Group continues to support and empower
1313
| Session | Title | Focus | Format |
1414
|---------|-------|-------|--------|
1515
| **14** | **Repository Walkthrough: Offchain and SDK building** | Deep dive into offchain architecture | Workshop |
16-
| **15** | **UI ↔ Smart Contracts: Wallets, Tx Building, and Submission** | End-to-end dApp interaction patterns + architecture trade-offs | Workshop |
16+
| **15** | **dApp Architecture: From Wallet to Backend** | Modular breakdown of full-stack dApp flow | Workshop |
17+
| **16** | **UI ↔ Smart Contracts: Wallets, Tx Building, and Submission** | End-to-end dApp interaction patterns + architecture trade-offs | Workshop |
1718

1819
## Session Details
1920

@@ -25,7 +26,15 @@ The Developer Experience (DevEx) Working Group continues to support and empower
2526
- Connecting SDKs to the blockchain for transaction building
2627
- **Deliverable**: Smart Contract Offchain Overview
2728

28-
### Session 15: UI ↔ Smart Contracts: Wallets, Tx Building, and Submission
29+
### Session 15: dApp Architecture: From Wallet to Backend
30+
- **Objective**: Explain the 4-layer architecture for Cardano dApps
31+
- **Key Topics**:
32+
- Frontend, Wallet, Backend, and Blockchain responsibilities
33+
- Failure handling in distributed systems
34+
- Polling vs. Webhooks for payment verification
35+
- **Deliverable**: [dApp Architecture Session Notes](./15-dapp-architecture-demo/session-notes/readme.md)
36+
37+
### Session 16: UI ↔ Smart Contracts: Wallets, Tx Building, and Submission
2938
- **Objective**: Teach the *practical* ways a UI app interacts with Cardano validators (Aiken/Plutus) using modern wallet + SDK flows, with clear trade-offs and diagrams.
3039
- **Key Topics**:
3140
- CIP-30 wallet connector fundamentals (connect, UTxOs, sign, submit)

0 commit comments

Comments
 (0)