The Miden Wallet Adapter is a modular TypeScript library that provides wallet integration capabilities for Miden blockchain applications. It's designed to connect Miden-compatible wallets to decentralized applications (dApps) in a standardized way.
- Setup: Wrap your app with
WalletProvider
and specify available wallet adapters - Connection: Use
WalletMultiButton
to connect or do so programmatically - Interaction: Use the
useWallet
hook to access wallet state and methods, such as the wallet's publicKey - Transactions: Use transaction types to submit a consume or send transaction via the wallet, or a generic transaction using a Miden
TransactionRequest
object
Connecting a wallet
const walletAdapter = new MidenWalletAdapter({ appName: 'Your Miden App', });
<WalletProvider wallets={[walletAdapter]}> // Defines which wallets are supported
<WalletModalProvider>
<>
Your app code...
<WalletMultiButton /> {/* Launches the WalletModal, prompts the user to connect their wallet */}
<>
</WalletModalProvider>
</WalletProvider>
Submitting a send transaction
const { wallet, publicKey } = useWallet();
const midenTransaction = new SendTransaction(
publicKey,
toAddress,
faucetId,
sharePrivately ? 'private' : 'public',
amount!
);
await wallet.adapter.requestSend(midenTransaction);
Submitting a custom transaction
const { wallet, publicKey } = useWallet();
const customTransaction = new CustomTransaction(
publicKey, // AccountId the transaction request will be executed against
transactionRequest // TransactionRequest object (will need to be generated using the Miden Web SDK)
);
await wallet.adapter.requestTransaction(customTransaction)
This repository contains three main packages:
- Purpose: Provides the foundational infrastructure and interfaces
- Key Components:
BaseWalletAdapter
: Abstract base class that all wallet adapters must extendWalletAdapter
interface: Defines the contract for wallet adapters- Event system: Uses
EventEmitter3
for wallet state changes (connect, disconnect, error, readyStateChange) - Type definitions: Network types (
Testnet
,Localnet
), decrypt permissions, transaction types - Error handling: Comprehensive error classes for different failure scenarios
- Purpose: React-specific hooks and context providers
- Key Components:
WalletProvider
: React context provider that manages wallet stateuseWallet
hook: Provides wallet state and methods to React components- Auto-connection: Handles automatic wallet reconnection on page load
- Local storage: Persists wallet selection across sessions
- Purpose: Pre-built React UI components for wallet interaction
- Key Components:
WalletModal
: Modal dialog for wallet selection and connectionWalletConnectButton
: Button component for initiating wallet connectionWalletMultiButton
: Multi-purpose button that handles connect/disconnect statesWalletListItem
: Individual wallet option in the selection modal
- Purpose: Specific implementation for the Miden Wallet
- Features:
- Detection: Automatically detects if Miden Wallet is installed
- Connection management: Handles wallet connection/disconnection
- Transaction support: Supports Miden-specific transaction types:
MidenSendTransaction
MidenConsumeTransaction
- Generic
MidenTransaction
- Permission management: Handles different decrypt permissions
- Error handling: Comprehensive error handling for wallet operations