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
4 changes: 4 additions & 0 deletions apps/docs/src/pages/en/packages/_meta.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default {

Check warning on line 1 in apps/docs/src/pages/en/packages/_meta.js

View workflow job for this annotation

GitHub Actions / build (20)

Assign object to a variable before exporting as module default

Check warning on line 1 in apps/docs/src/pages/en/packages/_meta.js

View workflow job for this annotation

GitHub Actions / build (20)

Assign object to a variable before exporting as module default
"midnight_setup": {
title: "Midnight Setup",
route: "/midnight_setup",
},
"wallet_widget": {
title: "Wallet Widget",
route: "/wallet_widget",
Expand Down
26 changes: 26 additions & 0 deletions apps/docs/src/pages/en/packages/midnight_setup/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {

Check warning on line 1 in apps/docs/src/pages/en/packages/midnight_setup/_meta.js

View workflow job for this annotation

GitHub Actions / build (20)

Assign object to a variable before exporting as module default

Check warning on line 1 in apps/docs/src/pages/en/packages/midnight_setup/_meta.js

View workflow job for this annotation

GitHub Actions / build (20)

Assign object to a variable before exporting as module default
"index": {
title: "Introduction",
route: "/",
},
"quick_start": {
title: "Quick Start",
route: "/quick_start",
},
"api_methods": {
title: "Core API Methods",
route: "/api_methods",
},
"wallet_integration": {
title: "Wallet Integration",
route: "/wallet_integration",
},
"examples": {
title: "Integration Examples",
route: "/examples",
},
"project_structure": {
title: "Project Structure",
route: "/project_structure",
},
};
25 changes: 25 additions & 0 deletions apps/docs/src/pages/en/packages/midnight_setup/api_methods.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Core API Methods
description: MidnightSetupAPI methods and provider setup
sidebarTitle: Core API Methods
---

# Core API Methods

## MidnightSetupAPI

| Method | Description | Usage |
|--------|-------------|-------|
| `deployContract(providers, contractInstance)` | Deploy a new contract | Creates new contract instance |
| `joinContract(providers, contractInstance, address)` | Join existing contract | Connect to deployed contract |
| `getContractState()` | Read contract state | Get current contract data |
| `getLedgerState()` | Read ledger state | Get blockchain data |

## Provider Setup

```typescript
import { setupProviders } from './lib/providers';

const providers = await setupProviders();
// Returns: MidnightSetupContractProviders
```
68 changes: 68 additions & 0 deletions apps/docs/src/pages/en/packages/midnight_setup/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Integration Examples
description: React hooks and integration examples
sidebarTitle: Integration Examples
---

# Integration Examples

## React Hook

```typescript
import { useMidnightContract } from './hooks/useMidnightContract';

function App() {
const { api, deployContract, joinContract } = useMidnightContract();

const handleDeploy = async () => {
const newApi = await deployContract();
console.log('Deployed:', newApi.deployedContractAddress);
};

return <button onClick={handleDeploy}>Deploy Contract</button>;
}
```

## Complete Example

```typescript
import { MidnightSetupAPI, useMidnightWallet } from '@meshsdk/midnight-setup';

function MyDApp() {
const { connectWallet, isConnected, walletState } = useMidnightWallet();

const handleDeployContract = async () => {
if (!isConnected) {
await connectWallet();
return;
}

// Setup providers
const providers = await setupProviders();

// Deploy contract
const api = await MidnightSetupAPI.deployContract(
providers,
contractInstance
);

console.log('Contract deployed at:', api.deployedContractAddress);
};

return (
<div>
<h1>My Midnight dApp</h1>
{!isConnected ? (
<button onClick={connectWallet}>Connect Wallet</button>
) : (
<div>
<p>Connected: {walletState.address}</p>
<button onClick={handleDeployContract}>
Deploy Contract
</button>
</div>
)}
</div>
);
}
```
53 changes: 53 additions & 0 deletions apps/docs/src/pages/en/packages/midnight_setup/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Midnight Setup
description: Complete development setup for building Midnight Network dApps
asIndexPage: true
sidebarTitle: Midnight Setup
---

# Midnight Setup

**Complete development setup for building Midnight Network dApps.**

## Overview

This comprehensive package provides everything you need to build decentralized applications (dApps) on the Midnight Network. Midnight is a next-generation blockchain that protects user, business, and transaction data through zero-knowledge (ZK) proofs, ensuring privacy without compromising data protection or ownership.

## What's Included

- **Core API** - Complete Midnight Network integration
- **Wallet Integration** - Full Lace Beta Wallet support
- **React Hooks** - Easy-to-use React components and hooks
- **CLI Tools** - Development utilities and helpers
- **TypeScript Support** - Full type safety and IntelliSense

## Quick Installation

- npm:
```bash
npm install @meshsdk/midnight-setup
```

- yarn:
```bash
yarn add @meshsdk/midnight-setup
```

## Getting Started

1. **[Quick Start](/en/packages/midnight_setup/quick_start)** - Installation and basic usage
2. **[Core API Methods](/en/packages/midnight_setup/api_methods)** - Understanding the API
3. **[Wallet Integration](/en/packages/midnight_setup/wallet_integration)** - Lace Wallet setup
4. **[Integration Examples](/en/packages/midnight_setup/examples)** - React hooks and examples
5. **[Project Structure](/en/packages/midnight_setup/project_structure)** - Understanding the codebase

## Key Features

- **Zero-knowledge privacy** - Built for Midnight Network
- **TypeScript support** - Full type safety
- **React hooks** - Easy integration
- **Wallet integration** - Lace Beta Wallet support
- **CLI tools** - Development utilities

Start building your Midnight dApp today! Explore the sections below to get started.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Project Structure
description: Understanding the monorepo structure and resources
sidebarTitle: Project Structure
---

# Project Structure

```
├── packages/
│ ├── api/ # Core API implementation
│ ├── ui/ # React example app
│ └── cli/ # Command-line tools
├── compact/ # Smart contract source
└── README.md
```

## Directory Overview

### packages/api/
Core API implementation containing:
- Contract deployment logic
- Provider management
- State management utilities

### packages/ui/
Example React application demonstrating:
- Wallet connection
- Contract deployment
- State reading and updates

### packages/cli/
Command-line tools for:
- Development utilities
- ZK parameter fetching
- Testing helpers

### compact/
Smart contract source code:
- Compact contracts
- Compilation artifacts
- Deployment scripts

## Resources

- [Midnight Network Docs](https://docs.midnight.network/)
- [Mesh SDK Documentation](https://docs.meshjs.dev/)
- [Lace Beta Wallet](https://chromewebstore.google.com/detail/lace-midnight-preview/hgeekaiplokcnmakghbdfbgnlfheichg)
63 changes: 63 additions & 0 deletions apps/docs/src/pages/en/packages/midnight_setup/quick_start.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Quick Start
description: Get started with @meshsdk/midnight-setup
sidebarTitle: Quick Start
---

# Quick Start

## Installation

```bash
yarn add @meshsdk/midnight-setup
```

## Basic Usage

```typescript
import { MidnightSetupAPI } from '@meshsdk/midnight-setup';

// Deploy a new contract
const api = await MidnightSetupAPI.deployContract(providers, contractInstance);

// Join an existing contract
const api = await MidnightSetupAPI.joinContract(providers, contractInstance, contractAddress);

// Get contract state
const state = await api.getContractState();

// Get ledger state
const ledgerState = await api.getLedgerState();
```

## What's Included

This monorepo contains everything you need to build Midnight Network dApps:

- **@meshsdk/midnight-setup** - Main npm package with API and types
- **packages/ui** - Example React application
- **packages/cli** - Command-line tools
- **packages/api** - Core API implementation

## Try the Project

To test the complete setup locally, use this repository as reference:

**Repository**: [https://github.com/MeshJS/midnight-setup](https://github.com/MeshJS/midnight-setup)

```bash
# 1. Install dependencies
yarn install

# 2. Build all packages
yarn build:all

# 3. Download fetch parameters
cd packages/cli && ./fetch-zk-params.sh

# 4. Start testnet with Docker
docker-compose -f testnet.yml up -d

# 5. Run the frontend
cd ../ui && yarn start
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: Wallet Integration
description: Complete Lace Beta Wallet integration for Midnight Network
sidebarTitle: Wallet Integration
---

# Lace Wallet Integration

This project includes a complete Lace Beta Wallet integration for Midnight Network:

## Wallet Features

| Feature | Description | Implementation |
|---------|-------------|----------------|
| **Connect Wallet** | Connect to Lace Beta Wallet | `wallet.enable()` |
| **Disconnect Wallet** | Disconnect from wallet | `wallet.disconnect()` |
| **Get Wallet State** | Retrieve wallet address and keys | `wallet.state()` |
| **Deploy Contract** | Deploy contracts through wallet | `wallet.submitTransaction()` |
| **Join Contract** | Join existing contracts | `wallet.balanceAndProveTransaction()` |
| **Balance Transactions** | Balance and prove transactions | Wallet API integration |

## Wallet Provider Setup

```typescript
// Connect to Lace Wallet
const wallet = window.midnight?.mnLace;
if (!wallet) {
throw new Error('Please install Lace Beta Wallet for Midnight Network');
}

// Enable wallet and get state
const walletAPI = await wallet.enable();
const walletState = await walletAPI.state();
const uris = await wallet.serviceUriConfig();
```

## React Wallet Hook

```typescript
import { useMidnightWallet } from './hooks/useMidnightWallet';

function App() {
const {
connectWallet,
disconnectWallet,
walletState,
isConnected
} = useMidnightWallet();

return (
<div>
{isConnected ? (
<button onClick={disconnectWallet}>Disconnect</button>
) : (
<button onClick={connectWallet}>Connect Wallet</button>
)}
</div>
);
}
```
Loading