WalletFactory
Midnight.js API Reference v2.0.2
Midnight.js API Reference / @midnight-ntwrk/midnight-js-testing / WalletFactory
Class: WalletFactory
Constructors
Constructor
new WalletFactory():
WalletFactory
Returns
WalletFactory
Methods
build()
staticbuild(env,walletLogLevel?):Promise<MidnightWallet>
Builds a wallet instance based on the provided environment configuration.
Parameters
env
Configuration for the wallet environment
walletLogLevel?
LogLevel = DEFAULT_WALLET_LOG_LEVEL
Optional log level for wallet operations
Returns
Promise<MidnightWallet>
A promise that resolves to the new wallet instance
buildFromEnvContext()
staticbuildFromEnvContext(env,seed?,walletLogLevel?):Promise<MidnightWallet>
Builds a wallet instance based on the provided environment configuration and optional seed.
Parameters
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<MidnightWallet>
A promise that resolves to the new wallet instance
buildFromSeed()
staticbuildFromSeed(env,seed,walletLogLevel?):Promise<MidnightWallet>
Builds a wallet instance from a seed based on the provided environment configuration.
Parameters
env
Configuration for the wallet environment
seed
string
Seed for wallet generation
walletLogLevel?
LogLevel = DEFAULT_WALLET_LOG_LEVEL
Optional log level for wallet operations
Returns
Promise<MidnightWallet>
A promise that resolves to the new wallet instance
buildFromSeedAndTryToRestoreState()
staticbuildFromSeedAndTryToRestoreState(env,seed,directoryPath?,filename?,walletLogLevel?):Promise<MidnightWallet>
Builds a wallet from a seed and attempts to restore its state from a saved file if available.
Parameters
env
Configuration containing indexer, node, and proof server details
seed
string
The seed to build the wallet from
directoryPath?
string = DEFAULT_WALLET_STATE_DIRECTORY
Directory path for wallet state file
filename?
string = ...
Filename for wallet state file
walletLogLevel?
LogLevel = DEFAULT_WALLET_LOG_LEVEL
Log level for wallet operations
Returns
Promise<MidnightWallet>
The built and initialized wallet
restore()
staticrestore(env,serialized,seed,trimTxHistory?,walletLogLevel?):Promise<MidnightWallet>
Restores a wallet instance from a serialized state based on the provided environment configuration.
Parameters
env
Configuration for the wallet environment
serialized
string
Serialized wallet state
seed
string
trimTxHistory?
boolean = true
Optional flag to trim the transaction history during restoration
walletLogLevel?
LogLevel = DEFAULT_WALLET_LOG_LEVEL
Optional log level for wallet operations
Returns
Promise<MidnightWallet>
A promise that resolves to the restored wallet instance