KmdAccountManager
Defined in: src/kmd-account-manager.ts:13
Provides abstractions over a KMD instance that makes it easier to get and manage accounts using KMD.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new KmdAccountManager(
clientManager):KmdAccountManager
Defined in: src/kmd-account-manager.ts:21
Create a new KMD manager.
Parameters
Section titled “Parameters”clientManager
Section titled “clientManager”A ClientManager client to use for algod and kmd clients
Returns
Section titled “Returns”KmdAccountManager
Methods
Section titled “Methods”getLocalNetDispenserAccount()
Section titled “getLocalNetDispenserAccount()”getLocalNetDispenserAccount():
Promise<AddressWithTransactionSigner>
Defined in: src/kmd-account-manager.ts:191
Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
Returns
Section titled “Returns”Promise<AddressWithTransactionSigner>
The default LocalNet dispenser account
Example
Section titled “Example”const dispenser = await kmdAccountManager.getLocalNetDispenserAccount()getOrCreateWalletAccount()
Section titled “getOrCreateWalletAccount()”getOrCreateWalletAccount(
name,fundWith?):Promise<AddressWithTransactionSigner>
Defined in: src/kmd-account-manager.ts:147
Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
This is useful to get idempotent accounts from LocalNet without having to specify the private key (which will change when resetting the LocalNet).
This significantly speeds up local dev time and improves experience since you can write code that just works first go without manual config in a fresh LocalNet.
If this is used via mnemonicAccountFromEnvironment, then you can even use the same code that runs on production without changes for local development!
Parameters
Section titled “Parameters”string
The name of the wallet to retrieve / create
fundWith?
Section titled “fundWith?”The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account
Returns
Section titled “Returns”Promise<AddressWithTransactionSigner>
An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
Example
Section titled “Example”// Idempotently get (if exists) or create (if it doesn't exist yet) an account by name using KMD// if creating it then fund it with 2 ALGO from the default dispenser accountconst newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo())// This will return the same account as above since the name matchesconst existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1')getWalletAccount()
Section titled “getWalletAccount()”getWalletAccount(
walletName,predicate?,sender?):Promise<AddressWithTransactionSigner|undefined>
Defined in: src/kmd-account-manager.ts:65
Returns an Algorand signing account with private key loaded from the given KMD wallet (identified by name).
Parameters
Section titled “Parameters”walletName
Section titled “walletName”string
The name of the wallet to retrieve an account from
predicate?
Section titled “predicate?”(account) => boolean
An optional filter to use to find the account (otherwise it will return a random account from the wallet)
sender?
Section titled “sender?”The optional sender address to use this signer for (aka a rekeyed account)
string | Address
Returns
Section titled “Returns”Promise<AddressWithTransactionSigner | undefined>
The signing account (with private key loaded) or undefined if no matching wallet or account was found
Example
Section titled “Example”const defaultDispenserAccount = await kmdAccountManager.getWalletAccount( 'unencrypted-default-wallet', a => a.status !== 'Offline' && a.amount > 1_000_000_000)kmd():
Promise<KmdClient>
Defined in: src/kmd-account-manager.ts:30
Returns
Section titled “Returns”Promise<KmdClient>