MidnightWalletProvider
Midnight.js API Reference v2.0.2
Midnight.js API Reference / @midnight-ntwrk/midnight-js-testing / MidnightWalletProvider
Class: MidnightWalletProvider
Provider class that implements wallet functionality for the Midnight network. Handles transaction balancing, submission, and wallet state management.
Implements
Implements
Implements
Implements
MidnightProviderWalletProviderResource
Properties
coinPublicKey
readonlycoinPublicKey:string
Wallet public coin key
Implementation of
encryptionPublicKey
readonlyencryptionPublicKey:string
Wallet EncryptionPublicKey
Implementation of
WalletProvider.encryptionPublicKey
env
readonlyenv:EnvironmentConfiguration
logger
logger:
Logger
wallet
readonlywallet:MidnightWallet
Methods
balanceTx()
balanceTx(
tx,newCoins):Promise<BalancedTransaction>
Balances an unbalanced transaction by adding necessary inputs and change outputs.
Parameters
tx
The unbalanced transaction to balance
newCoins
CoinInfo[]
Array of new coins to include in the transaction
Returns
Promise<BalancedTransaction>
A promise that resolves to the balanced transaction
Implementation of
close()
close():
Promise<void>
Closes the wallet and releases resources.
Returns
Promise<void>
A promise that resolves when the wallet is closed
Implementation of
Resource.close
start()
start(
waitForFundsInWallet):Promise<void>
Starts the wallet and optionally waits for funds to be available.
Parameters
waitForFundsInWallet
boolean = true
Whether to wait for funds to be available (default: true)
Returns
Promise<void>
A promise that resolves when the wallet is started and funds are available if requested
Implementation of
Resource.start
submitTx()
submitTx(
tx):Promise<string>
Submits a balanced transaction to the network.
Parameters
tx
The balanced transaction to submit
Returns
Promise<string>
A promise that resolves to the transaction hash
Implementation of
build()
staticbuild(logger,env,seed?,walletLogLevel?):Promise<MidnightWalletProvider>
Creates a new MidnightWalletProvider instance.
Parameters
logger
Logger
Logger instance for recording operations
env
Configuration for the wallet environment
seed?
string
Optional seed for wallet generation. If not provided, a new random wallet will be created
walletLogLevel?
LogLevel = DEFAULT_WALLET_LOG_LEVEL
Optional log level for wallet operations
Returns
Promise<MidnightWalletProvider>
A promise that resolves to the new wallet provider
Static
withWallet()
staticwithWallet(logger,env,wallet):Promise<MidnightWalletProvider>
Creates a new MidnightWalletProvider instance using an existing wallet.
Parameters
logger
Logger
Logger instance for recording operations
env
Configuration for the wallet environment
wallet
Existing wallet instance to use
Returns
Promise<MidnightWalletProvider>
A promise that resolves to the new wallet provider using the existing wallet