Skip to content
This new developer portal is under construction. For complete documentation, please refer to the old developer portal.

Account Management

Account management is one of the core capabilities provided by AlgoKit Utils. It allows you to create mnemonic, rekeyed, multisig, transaction signer, idempotent KMD and environment variable injected accounts that can be used to sign transactions as well as representing a sender address at the same time. This significantly simplifies management of transaction signing.

Account Manager Object

The AccountManager is a class that is used to get, create, and fund accounts and perform account-related actions such as funding. The AccountManager also keeps track of signers for each address so when using the AlgokitComposer to send transactions, a signer function does not need to manually be specified for each transaction - instead it can be inferred from the sender address automatically!

To get an instance of AccountManager, you can use either AlgorandClient via algorand.account or instantiate it directly (passing in a ClientManager):

import { AccountManager } from '@algorandfoundation/algokit-utils/types/account-manager';
const accountManager = new AccountManager(clientManager);

Transaction Signer Account

The core internal type that holds information about a signer/sender pair for a transaction is TransactionSignerAccount, which represents an algosdk.TransactionSigner (signer) along with a sender address (addr) as the encoded string address.

Many methods in AccountManager expose a TransactionSignerAccount.

SendTransactionFrom

SendTransactionFrom is a union of the following types that each represent an account that can both sign a transaction and represent a sender address:

  • Account - An in-built algosdk Account object
  • SigningAccount - An abstraction around algosdk.Account that supports rekeyed accounts
  • LogicSigAccount - An in-built algosdk algosdk.LogicSigAccount object
  • MultisigAccount - An abstraction around algosdk.MultisigMetadata, algosdk.makeMultiSigAccountTransactionSigner, algosdk.multisigAddress, algosdk.signMultisigTransaction and algosdk.appendSignMultisigTransaction that supports multisig accounts with one or more signers present
  • TransactionSignerAccount - An interface that provides a sender address alongside a transaction signer (e.g. for use with AtomicTransactionComposer or useWallet)

The use of in-built algosdk types like Account, LogicSigAccount and TransactionSigner is aligned to the Modularity principle. Allowing you to co-exist non AlgoKit Utils code with AlgoKit Utils functions.

AlgoKit Utils provides a few helper methods to take one of these SendTransactionFrom objects (that to reiterate uses the legacy imports to access):

  • algokit.getSenderAddress - Returns the public address of the sender the account represents
  • algokit.getSenderTransactionSigner - Returns a TransactionSigner to represent the signer of the account’ note: this is memoized so multiple calls to this for the same account will safely return the same TransactionSigner instance; this works nicely with AtomicTransactionComposer
  • algokit.signTransaction - Signs a single algosdk.Transaction object with the given account

Accounts

In order to get/register accounts for signing operations you can use the following methods on AccountManager (expressed here as algorand.account to denote the syntax via an AlgorandClient):

Dispenser

Rekey account

One of the unique features of Algorand is the ability to change the private key that can authorise transactions for an account. This is called rekeying.

You can issue a transaction to rekey an account by using the algokit.rekeyAccount(rekey, algod) function. The rekey parameter is an AlgoRekeyParams object with the following properties:

  • All properties in SendTransactionParams

  • from: SendTransactionFrom - The account that will be rekeyed

  • rekeyTo: SendTransactionFrom | string - The address of the account that will be used to authorise transactions for the rekeyed account going forward

  • transactionParams?: SuggestedParams - The optional transaction parameters

  • note?: TransactionNote - The transaction note

  • lease?: string | Uint8Array: A lease to assign to the transaction to enforce a mutually exclusive transaction (useful to prevent double-posting and other scenarios)

1
// Example
2
await algokit.rekeyAccount(
3
{
4
from: account,
5
rekeyTo: newAccount,
6
// Optionally specify transactionParams, note, lease and transaction sending parameters
7
},
8
algod,
9
);
10
11
const rekeyedAccount = algokit.rekeyedAccount(newAccount, account.addr);
12
// rekeyedAccount can be used to sign transactions on behalf of account...

KMD account management

When running LocalNet, you have an instance of the Key Management Daemon, which is useful for:

  • Accessing the private key of the default accounts that are pre-seeded with algos so that other accounts can be funded and it’s possible to use LocalNet
  • Idempotently creating new accounts against a name that will stay intact while the LocalNet instance is running without you needing to store private keys anywhere (i.e. completely automated)

The KMD SDK is fairly low level so to make use of it there is a fair bit of boilerplate code that’s needed. This code has been abstracted away into the KmdAccountManager class.

To get an instance of the KmdAccountManager class you can access it from AlgorandClient via algorand.account.kmd or instantiate it directly (passing in a ClientManager):

1
import { KmdAccountManager } from '@algorandfoundation/algokit-utils/types/kmd-account-manager';
2
3
// Algod client only
4
const kmdAccountManager = new KmdAccountManager(clientManager);

The methods that are available are:

1
// Get a wallet account that seeded the LocalNet network
2
const defaultDispenserAccount = await kmdAccountManager.getWalletAccount(
3
'unencrypted-default-wallet',
4
(a) => a.status !== 'Offline' && a.amount > 1_000_000_000,
5
)
6
// Same as above, but dedicated method call for convenience
7
const localNetDispenserAccount = await kmdAccountManager.getLocalNetDispenserAccount()
8
// Idempotently get (if exists) or create (if it doesn't exist yet) an account by name using KMD
9
// if creating it then fund it with 2 Algos from the default dispenser account
10
const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algos())
11
// This will return the same account as above since the name matches
12
const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1')

Some of this functionality is directly exposed from AccountManager, which has the added benefit of registering the account as a signer so they can be automatically used to sign transactions when using via AlgorandClient:

const localNetDispenser = await algorand.account.localNetDispenser(); // Get and register LocalNet dispenser
const dispenser = await algorand.account.dispenserFromEnvironment(); // Get and register a dispenser by environment variable, or if not set then LocalNet dispenser via KMD
const account1 = await algorand.account.fromKmd('account1', (2).algos()); // Get / create and register account from KMD idempotently by name