KmdAccountManager
@algorandfoundation/algokit-utils / types/kmd-account-manager / KmdAccountManager
types/kmd-account-manager.KmdAccountManager
Provides abstractions over a KMD instance that makes it easier to get and manage accounts using KMD.
Table of contents
Constructors
Properties
Methods
Constructors
constructor
• new KmdAccountManager(clientManager
): KmdAccountManager
Create a new KMD manager.
Parameters
Name | Type | Description |
---|---|---|
clientManager | ClientManager | A ClientManager client to use for algod and kmd clients |
Returns
Defined in
src/types/kmd-account-manager.ts:18
Properties
_clientManager
• Private
_clientManager: Omit
<ClientManager
, "kmd"
>
Defined in
src/types/kmd-account-manager.ts:11
_kmd
• Private
Optional
_kmd: null
| KmdClient
Defined in
src/types/kmd-account-manager.ts:12
Methods
getLocalNetDispenserAccount
▸ getLocalNetDispenserAccount(): Promise
<TransactionSignerAccount
& { account
: SigningAccount
}>
Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
Returns
Promise
<TransactionSignerAccount
& { account
: SigningAccount
}>
The default LocalNet dispenser account
Example
const dispenser = await kmdAccountManager.getLocalNetDispenserAccount();
Defined in
src/types/kmd-account-manager.ts:186
getOrCreateWalletAccount
▸ getOrCreateWalletAccount(name
, fundWith?
): Promise
<TransactionSignerAccount
& { account
: SigningAccount
}>
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
Name | Type | Description |
---|---|---|
name | string | The name of the wallet to retrieve / create |
fundWith? | AlgoAmount | 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
Promise
<TransactionSignerAccount
& { account
: SigningAccount
}>
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
// 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');
Defined in
src/types/kmd-account-manager.ts:135
getWalletAccount
▸ getWalletAccount(walletName
, predicate?
, sender?
): Promise
<undefined
| TransactionSignerAccount
& { account
: SigningAccount
}>
Returns an Algorand signing account with private key loaded from the given KMD wallet (identified by name).
Parameters
Name | Type | Description |
---|---|---|
walletName | string | The name of the wallet to retrieve an account from |
predicate? | (account : Record <string , any >) => boolean | An optional filter to use to find the account (otherwise it will return a random account from the wallet) |
sender? | string | Address | The optional sender address to use this signer for (aka a rekeyed account) |
Returns
Promise
<undefined
| TransactionSignerAccount
& { account
: SigningAccount
}>
The signing account (with private key loaded) or undefined if no matching wallet or account was found
Example
const defaultDispenserAccount = await kmdAccountManager.getWalletAccount( 'unencrypted-default-wallet', a => a.status !== 'Offline' && a.amount > 1_000_000_000,);
Defined in
src/types/kmd-account-manager.ts:62
kmd
▸ kmd(): Promise
<KmdClient
>
Returns
Promise
<KmdClient
>