Skip to content

@meshsdk/midnight-setup

Complete development setup for building Midnight Network dApps

npm versionLicense: MITTypeScript

Quick Start

Installation

yarn add @meshsdk/midnight-setup

Basic Usage

import{MidnightSetupAPI}from'@meshsdk/midnight-setup';// Deploy a new contractconstapi=awaitMidnightSetupAPI.deployContract(providers,contractInstance);// Join an existing contractconstapi=awaitMidnightSetupAPI.joinContract(providers,contractInstance,contractAddress);// Get contract stateconststate=awaitapi.getContractState();// Get ledger stateconstledgerState=awaitapi.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

Core API Methods

MidnightSetupAPI

MethodDescriptionUsage
deployContract(providers, contractInstance)Deploy a new contractCreates new contract instance
joinContract(providers, contractInstance, address)Join existing contractConnect to deployed contract
getContractState()Read contract stateGet current contract data
getLedgerState()Read ledger stateGet blockchain data

Provider Setup

import{setupProviders}from'./lib/providers';constproviders=awaitsetupProviders();// Returns: MidnightSetupContractProviders

Lace Wallet Integration

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

Wallet Features

FeatureDescriptionImplementation
Connect WalletConnect to Lace Beta Walletwallet.enable()
Disconnect WalletDisconnect from walletwallet.disconnect()
Get Wallet StateRetrieve wallet address and keyswallet.state()
Deploy ContractDeploy contracts through walletwallet.submitTransaction()
Join ContractJoin existing contractswallet.balanceAndProveTransaction()
Balance TransactionsBalance and prove transactionsWallet API integration

Wallet Provider Setup

// Connect to Lace Walletconstwallet=window.midnight?.mnLace;if(!wallet){thrownewError('Please install Lace Beta Wallet for Midnight Network');}// Enable wallet and get stateconstwalletAPI=awaitwallet.enable();constwalletState=awaitwalletAPI.state();consturis=awaitwallet.serviceUriConfig();

React Wallet Hook

import{useMidnightWallet}from'./hooks/useMidnightWallet';functionApp(){const{ connectWallet, disconnectWallet, walletState, isConnected }=useMidnightWallet();return(<div>{isConnected ? (<buttononClick={disconnectWallet}>Disconnect</button>) : (<buttononClick={connectWallet}>ConnectWallet</button>)}</div>);}

Project Structure

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

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

Integration Examples

React Hook

import{useMidnightContract}from'./hooks/useMidnightContract';functionApp(){const{ api, deployContract, joinContract }=useMidnightContract();consthandleDeploy=async()=>{constnewApi=awaitdeployContract();console.log('Deployed:',newApi.deployedContractAddress);};return<buttononClick={handleDeploy}>DeployContract</button>;}

Testing

Automated tests are not yet available. CI currently validates builds only. Planned test coverage is tracked in ROADMAP.md.

Try the Project

To test the complete setup locally, follow these steps strictly:

  • i) Clone the repository

  • using https:

git clone https://github.com/MeshJS/midnight-setup.git
  • using ssh:
git clone git@github.com:MeshJS/midnight-setup.git
  • ii) Navigate to the folder
cd midnight-setup
  • iii) Install dependencies
yarn install
  • iv) Set environment variable

  • TestNet:

cd packages/ui &&echo'VITE_NETWORK_ID="TestNet"'> .env
  • Undeployed
cd packages/ui &&echo'VITE_NETWORK_ID="Undeployed"'> .env
  • v) Build all packages
cd ../../ && yarn build:all
  • vi) Download fetch parameters
cd packages/cli && ./fetch-zk-params.sh
  • vii) Start testnet with Docker
docker-compose -f testnet.yml up -d
  • viii) Run the frontend
cd ../ui && yarn start

Configure Wallet

  • Open Midnight Lace Wallet
  • Go to SettingsNetwork
  • Select:
    • TestNet for Option A
    • Undeployed for Option B (Standalone infrastructure)

Recommendation: for full testing, use Standalone (local) and set the wallet to Undeployed with the local node in the Lace Wallet.

Lace Wallet (Other versions)

If you hit issues with Preview, install the legacy Lace Wallet extension:

  1. Sign in to download:

    • Lace Wallet versions
    • Note: it is no longer possible to download it for free (2.34.0); see the next step.
  2. Download .crx file with version 2.34.0 that can be found here.

  3. In Chrome, open chrome://extensions.

  4. Enable Developer mode (top-right).

  5. Click Load unpacked and select the extracted extension folder.

After installing, set the Lace Wallet to Undeployed and set the Proof Server to Local.

  • Now, you can deposit test tokens to your wallet:

  • Open a new terminal and go to cli folder:

cd packages/cli
  • Then run:
yarn deposit mn_shield-addr_undeployed...

Resources

Community


MeshJS Logo Powered by MeshJS Team

Built with ❤️ on Midnight Network

About

Complete development setup for building Midnight Network dApps.

Resources

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages