Skip to main content

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​

Properties​

coinPublicKey​

readonly coinPublicKey: string

Wallet public coin key

Implementation of​

WalletProvider.coinPublicKey


encryptionPublicKey​

readonly encryptionPublicKey: string

Wallet EncryptionPublicKey

Implementation of​

WalletProvider.encryptionPublicKey


env​

readonly env: EnvironmentConfiguration


logger​

logger: Logger


wallet​

readonly wallet: MidnightWallet

Methods​

balanceTx()​

balanceTx(tx, newCoins): Promise<BalancedTransaction>

Balances an unbalanced transaction by adding necessary inputs and change outputs.

Parameters​

tx​

UnbalancedTransaction

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​

WalletProvider.balanceTx


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​

BalancedTransaction

The balanced transaction to submit

Returns​

Promise<string>

A promise that resolves to the transaction hash

Implementation of​

MidnightProvider.submitTx


build()​

static build(logger, env, seed?, walletLogLevel?): Promise<MidnightWalletProvider>

Creates a new MidnightWalletProvider instance.

Parameters​

logger​

Logger

Logger instance for recording operations

env​

EnvironmentConfiguration

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()​

static withWallet(logger, env, wallet): Promise<MidnightWalletProvider>

Creates a new MidnightWalletProvider instance using an existing wallet.

Parameters​

logger​

Logger

Logger instance for recording operations

env​

EnvironmentConfiguration

Configuration for the wallet environment

wallet​

MidnightWallet

Existing wallet instance to use

Returns​

Promise<MidnightWalletProvider>

A promise that resolves to the new wallet provider using the existing wallet

Static​