AlgorandClient
@algorandfoundation/algokit-utils / types/algorand-client / AlgorandClient
types/algorand-client.AlgorandClient
A client that brokers easy access to Algorand functionality.
Table of contents
Section titled “Table of contents”Constructors
Section titled “Constructors”Properties
Section titled “Properties”- _accountManager
- _appDeployer
- _appManager
- _assetManager
- _cachedSuggestedParams
- _cachedSuggestedParamsExpiry
- _cachedSuggestedParamsTimeout
- _clientManager
- _defaultValidityWindow
- _errorTransformers
- _transactionCreator
- _transactionSender
Accessors
Section titled “Accessors”Methods
Section titled “Methods”- getSuggestedParams
- newGroup
- registerErrorTransformer
- setDefaultSigner
- setDefaultValidityWindow
- setSigner
- setSignerFromAccount
- setSuggestedParamsCache
- setSuggestedParamsCacheTimeout
- unregisterErrorTransformer
- defaultLocalNet
- fromClients
- fromConfig
- fromEnvironment
- mainNet
- testNet
Constructors
Section titled “Constructors”constructor
Section titled “constructor”• new AlgorandClient(config): AlgorandClient
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
config | AlgoConfig | AlgoSdkClients |
Returns
Section titled “Returns”Defined in
Section titled “Defined in”src/types/algorand-client.ts:40
Properties
Section titled “Properties”_accountManager
Section titled “_accountManager”• Private _accountManager: AccountManager
Defined in
Section titled “Defined in”src/types/algorand-client.ts:20
_appDeployer
Section titled “_appDeployer”• Private _appDeployer: AppDeployer
Defined in
Section titled “Defined in”src/types/algorand-client.ts:22
_appManager
Section titled “_appManager”• Private _appManager: AppManager
Defined in
Section titled “Defined in”src/types/algorand-client.ts:21
_assetManager
Section titled “_assetManager”• Private _assetManager: AssetManager
Defined in
Section titled “Defined in”src/types/algorand-client.ts:23
_cachedSuggestedParams
Section titled “_cachedSuggestedParams”• Private Optional _cachedSuggestedParams: SuggestedParams
Defined in
Section titled “Defined in”src/types/algorand-client.ts:27
_cachedSuggestedParamsExpiry
Section titled “_cachedSuggestedParamsExpiry”• Private Optional _cachedSuggestedParamsExpiry: Date
Defined in
Section titled “Defined in”src/types/algorand-client.ts:28
_cachedSuggestedParamsTimeout
Section titled “_cachedSuggestedParamsTimeout”• Private _cachedSuggestedParamsTimeout: number = 3_000
Defined in
Section titled “Defined in”src/types/algorand-client.ts:29
_clientManager
Section titled “_clientManager”• Private _clientManager: ClientManager
Defined in
Section titled “Defined in”src/types/algorand-client.ts:19
_defaultValidityWindow
Section titled “_defaultValidityWindow”• Private _defaultValidityWindow: undefined | bigint = undefined
Defined in
Section titled “Defined in”src/types/algorand-client.ts:31
_errorTransformers
Section titled “_errorTransformers”• Private _errorTransformers: Set<ErrorTransformer>
A set of error transformers to use when an error is caught in simulate or execute
registerErrorTransformer and unregisterErrorTransformer can be used to add and remove
error transformers from the set.
Defined in
Section titled “Defined in”src/types/algorand-client.ts:38
_transactionCreator
Section titled “_transactionCreator”• Private _transactionCreator: AlgorandClientTransactionCreator
Defined in
Section titled “Defined in”src/types/algorand-client.ts:25
_transactionSender
Section titled “_transactionSender”• Private _transactionSender: AlgorandClientTransactionSender
Defined in
Section titled “Defined in”src/types/algorand-client.ts:24
Accessors
Section titled “Accessors”account
Section titled “account”• get account(): AccountManager
Get or create accounts that can sign transactions.
Returns
Section titled “Returns”The AccountManager instance.
Example
const accountManager = AlgorandClient.mainNet().account;Defined in
Section titled “Defined in”src/types/algorand-client.ts:182
• get app(): AppManager
Methods for interacting with apps.
Returns
Section titled “Returns”The AppManager instance.
Example
const appManager = AlgorandClient.mainNet().app;Defined in
Section titled “Defined in”src/types/algorand-client.ts:202
appDeployer
Section titled “appDeployer”• get appDeployer(): AppDeployer
Methods for deploying apps and managing app deployment metadata.
Returns
Section titled “Returns”The AppDeployer instance.
Example
const deployer = AlgorandClient.mainNet().appDeployer;Defined in
Section titled “Defined in”src/types/algorand-client.ts:212
• get asset(): AssetManager
Methods for interacting with assets.
Returns
Section titled “Returns”The AssetManager instance.
Example
const assetManager = AlgorandClient.mainNet().asset;Defined in
Section titled “Defined in”src/types/algorand-client.ts:192
client
Section titled “client”• get client(): ClientManager
Get clients, including algosdk clients and app clients.
Returns
Section titled “Returns”The ClientManager instance.
Example
const clientManager = AlgorandClient.mainNet().client;Defined in
Section titled “Defined in”src/types/algorand-client.ts:172
createTransaction
Section titled “createTransaction”• get createTransaction(): AlgorandClientTransactionCreator
Methods for creating a transaction.
Returns
Section titled “Returns”AlgorandClientTransactionCreator
The AlgorandClientTransactionCreator instance.
Example
const payment = await AlgorandClient.mainNet().createTransaction.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: algo(1),});Defined in
Section titled “Defined in”src/types/algorand-client.ts:269
• get send(): AlgorandClientTransactionSender
Methods for sending a transaction.
Returns
Section titled “Returns”AlgorandClientTransactionSender
The AlgorandClientTransactionSender instance.
Example
const result = await AlgorandClient.mainNet().send.payment({ sender: 'SENDERADDRESS', receiver: 'RECEIVERADDRESS', amount: algo(1),});Defined in
Section titled “Defined in”src/types/algorand-client.ts:255
Methods
Section titled “Methods”getSuggestedParams
Section titled “getSuggestedParams”▸ getSuggestedParams(): Promise<SuggestedParams>
Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)
Returns
Section titled “Returns”Promise<SuggestedParams>
The suggested transaction parameters.
Example
const params = await AlgorandClient.mainNet().getSuggestedParams();Defined in
Section titled “Defined in”src/types/algorand-client.ts:151
newGroup
Section titled “newGroup”▸ newGroup(): TransactionComposer
Start a new TransactionComposer transaction group
Returns
Section titled “Returns”A new instance of TransactionComposer.
Example
const composer = AlgorandClient.mainNet().newGroup();const result = await composer.addTransaction(payment).send();Defined in
Section titled “Defined in”src/types/algorand-client.ts:234
registerErrorTransformer
Section titled “registerErrorTransformer”▸ registerErrorTransformer(transformer): void
Register a function that will be used to transform an error caught when simulating or executing
composed transaction groups made from newGroup
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
transformer | ErrorTransformer |
Returns
Section titled “Returns”void
Defined in
Section titled “Defined in”src/types/algorand-client.ts:220
setDefaultSigner
Section titled “setDefaultSigner”▸ setDefaultSigner(signer): AlgorandClient
Sets the default signer to use if no other signer is specified.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
signer | TransactionSigner | TransactionSignerAccount | The signer to use, either a TransactionSigner or a TransactionSignerAccount |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const signer = new SigningAccount(account, account.addr);const algorand = AlgorandClient.mainNet().setDefaultSigner(signer);Defined in
Section titled “Defined in”src/types/algorand-client.ts:74
setDefaultValidityWindow
Section titled “setDefaultValidityWindow”▸ setDefaultValidityWindow(validityWindow): AlgorandClient
Sets the default validity window for transactions.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
validityWindow | number | bigint | The number of rounds between the first and last valid rounds |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);Defined in
Section titled “Defined in”src/types/algorand-client.ts:59
setSigner
Section titled “setSigner”▸ setSigner(sender, signer): AlgorandClient
Tracks the given signer against the given sender for later signing.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
sender | string | Address | The sender address to use this signer for |
signer | TransactionSigner | The signer to sign transactions with for the given sender |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const signer = new SigningAccount(account, account.addr);const algorand = AlgorandClient.mainNet().setSigner(signer.addr, signer.signer);Defined in
Section titled “Defined in”src/types/algorand-client.ts:110
setSignerFromAccount
Section titled “setSignerFromAccount”▸ setSignerFromAccount(account): AlgorandClient
Tracks the given account (object that encapsulates an address and a signer) for later signing.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
account | MultisigAccount | default | SigningAccount | TransactionSignerAccount | LogicSigAccount | The account to register, which can be a TransactionSignerAccount or a algosdk.Account, algosdk.LogicSigAccount, SigningAccount or MultisigAccount |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const accountManager = AlgorandClient.mainNet() .setSignerFromAccount(algosdk.generateAccount()) .setSignerFromAccount(new algosdk.LogicSigAccount(program, args)) .setSignerFromAccount(new SigningAccount(account, sender)) .setSignerFromAccount( new MultisigAccount({ version: 1, threshold: 1, addrs: ['ADDRESS1...', 'ADDRESS2...'] }, [ account1, account2, ]), ) .setSignerFromAccount({ addr: 'SENDERADDRESS', signer: transactionSigner });Defined in
Section titled “Defined in”src/types/algorand-client.ts:94
setSuggestedParamsCache
Section titled “setSuggestedParamsCache”▸ setSuggestedParamsCache(suggestedParams, until?): AlgorandClient
Sets a cache value to use for suggested transaction params.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
suggestedParams | SuggestedParams | The suggested params to use |
until? | Date | A date until which to cache, or if not specified then the timeout is used |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const algorand = AlgorandClient.mainNet().setSuggestedParamsCache( suggestedParams, new Date(+new Date() + 3_600_000),);Defined in
Section titled “Defined in”src/types/algorand-client.ts:125
setSuggestedParamsCacheTimeout
Section titled “setSuggestedParamsCacheTimeout”▸ setSuggestedParamsCacheTimeout(timeout): AlgorandClient
Sets the timeout for caching suggested params.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
timeout | number | The timeout in milliseconds |
Returns
Section titled “Returns”The AlgorandClient so method calls can be chained
Example
const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000);Defined in
Section titled “Defined in”src/types/algorand-client.ts:140
unregisterErrorTransformer
Section titled “unregisterErrorTransformer”▸ unregisterErrorTransformer(transformer): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
transformer | ErrorTransformer |
Returns
Section titled “Returns”void
Defined in
Section titled “Defined in”src/types/algorand-client.ts:224
defaultLocalNet
Section titled “defaultLocalNet”▸ defaultLocalNet(): AlgorandClient
Creates an AlgorandClient pointing at default LocalNet ports and API token.
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const algorand = AlgorandClient.defaultLocalNet();Defined in
Section titled “Defined in”src/types/algorand-client.ts:281
fromClients
Section titled “fromClients”▸ fromClients(clients): AlgorandClient
Creates an AlgorandClient pointing to the given client(s).
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
clients | AlgoSdkClients | The clients to use. |
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });Defined in
Section titled “Defined in”src/types/algorand-client.ts:324
fromConfig
Section titled “fromConfig”▸ fromConfig(config): AlgorandClient
Creates an AlgorandClient from the given config.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
config | AlgoConfig | The config to use. |
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });Defined in
Section titled “Defined in”src/types/algorand-client.ts:358
fromEnvironment
Section titled “fromEnvironment”▸ fromEnvironment(): AlgorandClient
Creates an AlgorandClient loading the configuration from environment variables.
Retrieve configurations from environment variables when defined or get default LocalNet configuration if they aren’t defined.
Expects to be called from a Node.js environment.
If process.env.ALGOD_SERVER is defined it will use that along with optional process.env.ALGOD_PORT and process.env.ALGOD_TOKEN.
If process.env.INDEXER_SERVER is defined it will use that along with optional process.env.INDEXER_PORT and process.env.INDEXER_TOKEN.
If either aren’t defined it will use the default LocalNet config.
It will return a KMD configuration that uses process.env.KMD_PORT (or port 4002) if process.env.ALGOD_SERVER is defined,
otherwise it will use the default LocalNet config unless it detects testnet or mainnet.
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const client = AlgorandClient.fromEnvironment();Defined in
Section titled “Defined in”src/types/algorand-client.ts:347
mainNet
Section titled “mainNet”▸ mainNet(): AlgorandClient
Creates an AlgorandClient pointing at MainNet using AlgoNode.
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const algorand = AlgorandClient.mainNet();Defined in
Section titled “Defined in”src/types/algorand-client.ts:309
testNet
Section titled “testNet”▸ testNet(): AlgorandClient
Creates an AlgorandClient pointing at TestNet using AlgoNode.
Returns
Section titled “Returns”An instance of the AlgorandClient.
Example
const algorand = AlgorandClient.testNet();