yarn add @meshsdk/midnight-setupimport { 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();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
| 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 |
import { setupProviders } from './lib/providers';
const providers = await setupProviders();
// Returns: MidnightSetupContractProvidersThis project includes a complete Lace Beta Wallet integration for Midnight Network:
| 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 |
// 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();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>
);
}├── packages/
│ ├── api/ # Core API implementation
│ ├── ui/ # React example app
│ └── cli/ # Command-line tools
├── compact/ # Smart contract source
└── README.md
- 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
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>;
}To test the complete setup locally, follow these steps strictly:
-
- Clone the repository
-
using https:
git clone https://github.com/MeshJS/midnight-setup.git- using ssh:
git clone [email protected]:MeshJS/midnight-setup.git-
- Navigate to the folder
cd midnight-setup-
- Install dependencies
yarn install-
- Set environment variable
cd packages/ui && echo 'VITE_NETWORK_ID="TestNet"' > .env-
- Build all packages
cd ../../ && yarn build:all-
- Download fetch parameters
cd packages/cli && ./fetch-zk-params.sh-
- Start testnet with Docker
docker-compose -f testnet.yml up -d-
- Run the frontend
cd ../ui && yarn start Powered by MeshJS Team
Built with ❤️ on Midnight Network