AccountManager
Defined in: src/account-manager.ts:48
Creates and keeps track of signing accounts that can sign transactions for a sending address.
- KmdAccountManager for KMD-specific account management
- AlgorandClient for the main entry point that provides access to this manager
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AccountManager(
clientManager,config):AccountManager
Defined in: src/account-manager.ts:63
Create a new account manager.
Parameters
Section titled “Parameters”clientManager
Section titled “clientManager”The ClientManager client to use for algod and kmd clients
config
Section titled “config”AccountManagerConfig
Returns
Section titled “Returns”AccountManager
Example
Section titled “Example”const accountManager = new AccountManager(clientManager)Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get kmd():
KmdAccountManager
Defined in: src/account-manager.ts:85
KMD account manager that allows you to easily get and create accounts using KMD.
Example
Section titled “Example”const kmdManager = accountManager.kmd;Returns
Section titled “Returns”The KmdAccountManager instance.
Methods
Section titled “Methods”dispenserFromEnvironment()
Section titled “dispenserFromEnvironment()”dispenserFromEnvironment():
Promise<AddressWithTransactionSigner>
Defined in: src/account-manager.ts:474
Returns an account (with private key loaded) that can act as a dispenser from environment variables, or against default LocalNet if no environment variables present.
Note: requires a Node.js environment to execute.
If present, it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER if it’s a rekeyed account.
Returns
Section titled “Returns”Promise<AddressWithTransactionSigner>
The account
Example
Section titled “Example”const account = await accountManager.dispenserFromEnvironment()ensureFunded()
Section titled “ensureFunded()”ensureFunded(
accountToFund,dispenserAccount,minSpendingBalance,options?):Promise<object&EnsureFundedResult|undefined>
Defined in: src/account-manager.ts:594
Funds a given account using a dispenser account as a funding source such that the given account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement).
https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
Parameters
Section titled “Parameters”accountToFund
Section titled “accountToFund”The account to fund
string | Address
dispenserAccount
Section titled “dispenserAccount”The account to use as a dispenser funding source
string | Address
minSpendingBalance
Section titled “minSpendingBalance”The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
options?
Section titled “options?”object & SendParams & Omit<CommonTransactionParams, "sender">
Optional parameters to control the funding increment, transaction or execution of the transaction
Returns
Section titled “Returns”Promise<object & EnsureFundedResult | undefined>
- The result of executing the dispensing transaction and the
amountFundedif funds were needed. undefinedif no funds were needed.
Example
Section titled “Example”// Basic exampleawait accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1))// With configurationawait accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1), { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true })ensureFundedFromEnvironment()
Section titled “ensureFundedFromEnvironment()”ensureFundedFromEnvironment(
accountToFund,minSpendingBalance,options?):Promise<object&EnsureFundedResult|undefined>
Defined in: src/account-manager.ts:656
Funds a given account using a dispenser account retrieved from the environment,
per the dispenserFromEnvironment method, as a funding source such that
the given account has a certain amount of Algo free to spend (accounting for
Algo locked in minimum balance requirement).
Note: requires a Node.js environment to execute.
The dispenser account is retrieved from the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER if it’s a rekeyed account, or against default LocalNet if no environment variables present.
https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
Parameters
Section titled “Parameters”accountToFund
Section titled “accountToFund”The account to fund
string | Address
minSpendingBalance
Section titled “minSpendingBalance”The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
options?
Section titled “options?”object & SendParams & Omit<CommonTransactionParams, "sender">
Optional parameters to control the funding increment, transaction or execution of the transaction
Returns
Section titled “Returns”Promise<object & EnsureFundedResult | undefined>
- The result of executing the dispensing transaction and the
amountFundedif funds were needed. undefinedif no funds were needed.
Example
Section titled “Example”// Basic exampleawait accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1))// With configurationawait accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1), { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true })ensureFundedFromTestNetDispenserApi()
Section titled “ensureFundedFromTestNetDispenserApi()”ensureFundedFromTestNetDispenserApi(
accountToFund,dispenserClient,minSpendingBalance,options?):Promise<EnsureFundedResult|undefined>
Defined in: src/account-manager.ts:712
Funds a given account using the TestNet Dispenser API as a funding source such that the account has a certain amount of Algo free to spend (accounting for Algo locked in minimum balance requirement).
https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
Parameters
Section titled “Parameters”accountToFund
Section titled “accountToFund”The account to fund
string | Address
dispenserClient
Section titled “dispenserClient”The TestNet dispenser funding client
minSpendingBalance
Section titled “minSpendingBalance”The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
options?
Section titled “options?”Optional parameters to control the funding increment, transaction or execution of the transaction
minFundingIncrement?
Section titled “minFundingIncrement?”Returns
Section titled “Returns”Promise<EnsureFundedResult | undefined>
- The result of executing the dispensing transaction and the
amountFundedif funds were needed. undefinedif no funds were needed.
Example
Section titled “Example”// Basic exampleawait accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1))// With configurationawait accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1), { minFundingIncrement: algokit.algo(2) })fromEnvironment()
Section titled “fromEnvironment()”fromEnvironment(
name,fundWith?):Promise<AddressWithTransactionSigner>
Defined in: src/account-manager.ts:347
Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
Note: This function expects to run in a Node.js environment.
Convention:
Section titled “Convention:”- Non-LocalNet: will load process.env[‘{NAME}_MNEMONIC’] as a mnemonic secret; Note: Be careful how the mnemonic is handled, never commit it into source control and ideally load it via a secret storage service rather than the file system. If process.env[‘{NAME}_SENDER’] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
- LocalNet: will load the account from a KMD wallet called {NAME} and if that wallet doesn’t exist it will create it and fund the account for you
This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
Parameters
Section titled “Parameters”string
The name identifier of the account
fundWith?
Section titled “fundWith?”The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account
Returns
Section titled “Returns”Promise<AddressWithTransactionSigner>
The account
Example
Section titled “Example”If you have a mnemonic secret loaded into process.env.MY_ACCOUNT_MNEMONIC then you can call the following to get that private key loaded into an account object:
const account = await accountManager.fromEnvironment('MY_ACCOUNT')If that code runs against LocalNet then a wallet called MY_ACCOUNT will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.
If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address.
fromKmd()
Section titled “fromKmd()”fromKmd(
name,predicate?,sender?):Promise<Address&AddressWithTransactionSigner&object>
Defined in: src/account-manager.ts:382
Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
Parameters
Section titled “Parameters”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<Address & AddressWithTransactionSigner & object>
The account
Example
Section titled “Example”const defaultDispenserAccount = await accountManager.fromKmd('unencrypted-default-wallet', a => a.status !== 'Offline' && a.amount > 1_000_000_000)fromMnemonic()
Section titled “fromMnemonic()”fromMnemonic(
mnemonicSecret,sender?):AddressWithTransactionSigner
Defined in: src/account-manager.ts:290
Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
Parameters
Section titled “Parameters”mnemonicSecret
Section titled “mnemonicSecret”string
The mnemonic secret representing the private key of an account; Note: Be careful how the mnemonic is handled, never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
sender?
Section titled “sender?”The optional sender address to use this signer for (aka a rekeyed account)
string | Address
Returns
Section titled “Returns”The account
Example
Section titled “Example”const account = accountManager.fromMnemonic("mnemonic secret ...")const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")getAccount()
Section titled “getAccount()”getAccount(
sender):AddressWithTransactionSigner
Defined in: src/account-manager.ts:225
Returns the AddressWithSigner for the given sender address.
If no signer has been registered for that address then an error is thrown.
Parameters
Section titled “Parameters”sender
Section titled “sender”The sender address
Returns
Section titled “Returns”The AddressWithSigner or throws an error if not found
Example
Section titled “Example”const sender = accountManager.random()// ...// Returns the `AddressWithSigner` for `sender` that has previously been registeredconst account = accountManager.getAccount(sender)getInformation()
Section titled “getInformation()”getInformation(
sender):Promise<AccountInformation>
Defined in: src/account-manager.ts:244
Returns the given sender account’s current status, balance and spendable amounts.
Parameters
Section titled “Parameters”sender
Section titled “sender”The account / address to look up
Returns
Section titled “Returns”Promise<AccountInformation>
The account information
Example
Section titled “Example”const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";const accountInfo = await accountManager.getInformation(address);getSigner()
Section titled “getSigner()”getSigner(
sender):TransactionSigner
Defined in: src/account-manager.ts:205
Returns the TransactionSigner for the given sender address, ready to sign a transaction for that sender.
If no signer has been registered for that address then the default signer is used if registered and if not then an error is thrown.
Parameters
Section titled “Parameters”sender
Section titled “sender”The sender address
Returns
Section titled “Returns”The TransactionSigner or throws an error if not found and no default signer is set
Example
Section titled “Example”const signer = accountManager.getSigner("SENDERADDRESS")localNetDispenser()
Section titled “localNetDispenser()”localNetDispenser():
Promise<Address&AddressWithTransactionSigner&object>
Defined in: src/account-manager.ts:493
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<Address & AddressWithTransactionSigner & object>
The account
Example
Section titled “Example”const account = await accountManager.localNetDispenser()logicsig()
Section titled “logicsig()”logicsig(
program,args?):Address&AddressWithTransactionSigner&object
Defined in: src/account-manager.ts:420
Tracks and returns an account that represents a logic signature.
Parameters
Section titled “Parameters”program
Section titled “program”Uint8Array
The bytes that make up the compiled logic signature
Uint8Array<ArrayBufferLike>[]
The (binary) arguments to pass into the logic signature
Returns
Section titled “Returns”Address & AddressWithTransactionSigner & object
A logic signature account wrapper
Example
Section titled “Example”const account = accountManager.logicsig(program, [new Uint8Array(3, ...)])multisig()
Section titled “multisig()”multisig(
multisigParams,subSigners):Address&AddressWithTransactionSigner&object
Defined in: src/account-manager.ts:405
Tracks and returns an account that supports partial or full multisig signing.
Parameters
Section titled “Parameters”multisigParams
Section titled “multisigParams”The parameters that define the multisig account
subSigners
Section titled “subSigners”object[]
The signers that are currently present
Returns
Section titled “Returns”Address & AddressWithTransactionSigner & object
A multisig account wrapper
Example
Section titled “Example”const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [(await accountManager.fromEnvironment('ACCOUNT1')).account])random()
Section titled “random()”random():
Address&object
Defined in: src/account-manager.ts:433
Tracks and returns a new, random Algorand account with secret key loaded.
Returns
Section titled “Returns”Address & object
The account
Example
Section titled “Example”const account = accountManager.random()rekeyAccount()
Section titled “rekeyAccount()”rekeyAccount(
account,rekeyTo,options?):Promise<{confirmation:PendingTransactionResponse;confirmations:PendingTransactionResponse[];groupId:string|undefined;returns?:ABIReturn[];transaction:Transaction;transactions:Transaction[];txIds:string[]; }>
Defined in: src/account-manager.ts:536
Rekey an account to a new address.
Note: Please be careful with this function and be sure to read the official rekey guidance.
Parameters
Section titled “Parameters”account
Section titled “account”The account to rekey
string | Address
rekeyTo
Section titled “rekeyTo”The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward.
If a signing account is provided that will now be tracked as the signer for account in this AccountManager
string | Address | AddressWithTransactionSigner
options?
Section titled “options?”Omit<CommonTransactionParams, "sender"> & SendParams
Any parameters to control the transaction or execution of the transaction
Returns
Section titled “Returns”Promise<{ confirmation: PendingTransactionResponse; confirmations: PendingTransactionResponse[]; groupId: string | undefined; returns?: ABIReturn[]; transaction: Transaction; transactions: Transaction[]; txIds: string[]; }>
The result of the transaction and the transaction that was sent
Examples
Section titled “Examples”await accountManager.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"})await accountManager.rekeyAccount({account: account1, rekeyTo: newSignerAccount})await accountManager.rekeyAccount({ account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS", lease: 'lease', note: 'note', firstValidRound: 1000n, validityWindow: 10, extraFee: (1000).microAlgo(), staticFee: (1000).microAlgo(), // Max fee doesn't make sense with extraFee AND staticFee // already specified, but here for completeness maxFee: (3000).microAlgo(), maxRoundsToWaitForConfirmation: 5, suppressLog: true,})rekeyed()
Section titled “rekeyed()”rekeyed(
sender,account):Address&AddressWithTransactionSigner&object
Defined in: src/account-manager.ts:316
Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender.
Parameters
Section titled “Parameters”sender
Section titled “sender”The sender address to use as the new sender
string | Address
account
Section titled “account”The account to use as the signer for this new rekeyed account
Returns
Section titled “Returns”Address & AddressWithTransactionSigner & object
The account
Example
Section titled “Example”const account = accountManager.fromMnemonic("mnemonic secret ...")const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")setDefaultSigner()
Section titled “setDefaultSigner()”setDefaultSigner(
signer):AccountManager
Defined in: src/account-manager.ts:105
Sets the default signer to use if no other signer is specified.
If this isn’t set an a transaction needs signing for a given sender
then an error will be thrown from getSigner / getAccount.
Parameters
Section titled “Parameters”signer
Section titled “signer”The signer to use, either a TransactionSigner or a AddressWithSigner
AddressWithTransactionSigner | TransactionSigner
Returns
Section titled “Returns”AccountManager
The AccountManager so method calls can be chained
Example
Section titled “Example”const signer = accountManager.random() // Can be anything that returns a `TransactionSigner` or `AddressWithSigner`accountManager.setDefaultSigner(signer)
// When signing a transaction, if there is no signer registered for the sender then the default signer will be usedconst signer = accountManager.getSigner("SENDERADDRESS")setSigner()
Section titled “setSigner()”setSigner(
sender,signer):AccountManager
Defined in: src/account-manager.ts:168
Tracks the given TransactionSigner against the given sender address for later signing.
Parameters
Section titled “Parameters”sender
Section titled “sender”The sender address to use this signer for
string | Address
signer
Section titled “signer”The TransactionSigner to sign transactions with for the given sender
Returns
Section titled “Returns”AccountManager
The AccountManager instance for method chaining
Example
Section titled “Example”const accountManager = new AccountManager(clientManager) .setSigner("SENDERADDRESS", transactionSigner)setSignerFromAccount()
Section titled “setSignerFromAccount()”setSignerFromAccount(
account):AccountManager
Defined in: src/account-manager.ts:152
Tracks the given account for later signing.
Note: If you are generating accounts via the various methods on AccountManager
(like random, fromMnemonic, logicsig, etc.) then they automatically get tracked.
Parameters
Section titled “Parameters”account
Section titled “account”The account to register, which can be a AddressWithSigner or
a algosdk.Account, algosdk.LogicSigAccount, SigningAccount or MultisigAccount
MultisigAccount | AddressWithTransactionSigner | LogicSigAccount
Returns
Section titled “Returns”AccountManager
The AccountManager instance for method chaining
Example
Section titled “Example”const accountManager = new AccountManager(clientManager) .setSignerFromAccount(algosdk.generateAccount()) .setSignerFromAccount(new algosdk.LogicSigAccount(program, args)) .setSignerFromAccount(new SigningAccount(mnemonic, sender)) .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2])) .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})setSigners()
Section titled “setSigners()”setSigners(
anotherAccountManager,overwriteExisting?):AccountManager
Defined in: src/account-manager.ts:185
Takes all registered signers from the given AccountManager and adds them to this AccountManager.
This is useful for situations where you have multiple contexts you are building accounts in such as unit tests.
Parameters
Section titled “Parameters”anotherAccountManager
Section titled “anotherAccountManager”AccountManager
Another account manager with signers registered
overwriteExisting?
Section titled “overwriteExisting?”boolean = true
Whether or not to overwrite any signers that have the same sender address with the ones in the other account manager or not (default: true)
Returns
Section titled “Returns”AccountManager
The AccountManager instance for method chaining
Example
Section titled “Example”accountManager2.setSigners(accountManager1);