@midnight-ntwrk/wallet-sdk-dust-wallet
v4.0.0
Published
Manages dust (transaction fees) on the Midnight network.
Readme
@midnight-ntwrk/wallet-sdk-dust-wallet
Manages dust (transaction fees) on the Midnight network.
Installation
npm install @midnight-ntwrk/wallet-sdk-dust-walletOverview
The Dust Wallet handles dust operations on the Midnight network. Dust is required to pay transaction fees. This package provides:
- Dust coin management and tracking
- Balance synchronization with the network
- Transaction fee calculation
- Dust generation from Night UTXOs
- Fee balancing for transactions
Usage
Starting the Wallet
import { DustWallet } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
await dustWallet.start(dustSecretKey);Observing State
dustWallet.state.subscribe((state) => {
console.log('Progress:', state.state.progress);
console.log('Balance:', state.state.balance);
console.log('Dust Address:', state.dustAddress);
});
// Or wait for sync
const syncedState = await dustWallet.waitForSyncedState();Balancing Transaction Fees
// Add fee balancing to a transaction
const feeBalancingTx = await dustWallet.balanceTransactions(dustSecretKey, [transactionToBalance], ttl);Calculating Fees
// Calculate the fee for a transaction only (does not include the balancing transaction fee)
const fee = await dustWallet.calculateFee([transaction]);
// Estimate the total fee including the balancing transaction fee
// ttl and currentTime are optional (default: 1 hour from now, and current block timestamp)
const totalFee = await dustWallet.estimateFee(dustSecretKey, [transaction]);
// With explicit ttl and currentTime
const totalFeeWithOptions = await dustWallet.estimateFee(dustSecretKey, [transaction], ttl, currentTime);Dust Generation
Register Night UTXOs to generate dust:
const dustGenerationTx = await dustWallet.createDustGenerationTransaction(
previousState,
ttl,
nightUtxos,
nightVerifyingKey,
dustReceiverAddress,
);
// Add signature for dust registration
const signedTx = await dustWallet.addDustGenerationSignature(dustGenerationTx, signature);Exports
DustWallet- Main wallet classDustWalletState- Wallet state typeDustCoreWallet- Core wallet implementationKeys- Key management utilitiesSimulator- Dust simulation utilitiesSyncService- Synchronization serviceTransacting- Transaction utilitiesCoinsAndBalances- Coin and balance management
V1 Builder
Use the V1 builder pattern for wallet construction:
import { V1Builder, RunningV1Variant } from '@midnight-ntwrk/wallet-sdk-dust-wallet';
// Build a V1 dust wallet variantLicense
Apache-2.0
