Skip to content

AlgorandClient

@algorandfoundation/algokit-utils / types/algorand-client / AlgorandClient

types/algorand-client.AlgorandClient

A client that brokers easy access to Algorand functionality.

new AlgorandClient(config): AlgorandClient

NameType
configAlgoConfig | AlgoSdkClients

AlgorandClient

src/types/algorand-client.ts:40

Private _accountManager: AccountManager

src/types/algorand-client.ts:20


Private _appDeployer: AppDeployer

src/types/algorand-client.ts:22


Private _appManager: AppManager

src/types/algorand-client.ts:21


Private _assetManager: AssetManager

src/types/algorand-client.ts:23


Private Optional _cachedSuggestedParams: SuggestedParams

src/types/algorand-client.ts:27


Private Optional _cachedSuggestedParamsExpiry: Date

src/types/algorand-client.ts:28


Private _cachedSuggestedParamsTimeout: number = 3_000

src/types/algorand-client.ts:29


Private _clientManager: ClientManager

src/types/algorand-client.ts:19


Private _defaultValidityWindow: undefined | bigint = undefined

src/types/algorand-client.ts:31


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.

src/types/algorand-client.ts:38


Private _transactionCreator: AlgorandClientTransactionCreator

src/types/algorand-client.ts:25


Private _transactionSender: AlgorandClientTransactionSender

src/types/algorand-client.ts:24

get account(): AccountManager

Get or create accounts that can sign transactions.

AccountManager

The AccountManager instance.

Example

const accountManager = AlgorandClient.mainNet().account;

src/types/algorand-client.ts:182


get app(): AppManager

Methods for interacting with apps.

AppManager

The AppManager instance.

Example

const appManager = AlgorandClient.mainNet().app;

src/types/algorand-client.ts:202


get appDeployer(): AppDeployer

Methods for deploying apps and managing app deployment metadata.

AppDeployer

The AppDeployer instance.

Example

const deployer = AlgorandClient.mainNet().appDeployer;

src/types/algorand-client.ts:212


get asset(): AssetManager

Methods for interacting with assets.

AssetManager

The AssetManager instance.

Example

const assetManager = AlgorandClient.mainNet().asset;

src/types/algorand-client.ts:192


get client(): ClientManager

Get clients, including algosdk clients and app clients.

ClientManager

The ClientManager instance.

Example

const clientManager = AlgorandClient.mainNet().client;

src/types/algorand-client.ts:172


get createTransaction(): AlgorandClientTransactionCreator

Methods for creating a transaction.

AlgorandClientTransactionCreator

The AlgorandClientTransactionCreator instance.

Example

const payment = await AlgorandClient.mainNet().createTransaction.payment({
sender: 'SENDERADDRESS',
receiver: 'RECEIVERADDRESS',
amount: algo(1),
});

src/types/algorand-client.ts:269


get send(): AlgorandClientTransactionSender

Methods for sending a transaction.

AlgorandClientTransactionSender

The AlgorandClientTransactionSender instance.

Example

const result = await AlgorandClient.mainNet().send.payment({
sender: 'SENDERADDRESS',
receiver: 'RECEIVERADDRESS',
amount: algo(1),
});

src/types/algorand-client.ts:255

getSuggestedParams(): Promise<SuggestedParams>

Get suggested params for a transaction (either cached or from algod if the cache is stale or empty)

Promise<SuggestedParams>

The suggested transaction parameters.

Example

const params = await AlgorandClient.mainNet().getSuggestedParams();

src/types/algorand-client.ts:151


newGroup(): TransactionComposer

Start a new TransactionComposer transaction group

TransactionComposer

A new instance of TransactionComposer.

Example

const composer = AlgorandClient.mainNet().newGroup();
const result = await composer.addTransaction(payment).send();

src/types/algorand-client.ts:234


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

NameType
transformerErrorTransformer

void

src/types/algorand-client.ts:220


setDefaultSigner(signer): AlgorandClient

Sets the default signer to use if no other signer is specified.

NameTypeDescription
signerTransactionSigner | TransactionSignerAccountThe signer to use, either a TransactionSigner or a TransactionSignerAccount

AlgorandClient

The AlgorandClient so method calls can be chained

Example

const signer = new SigningAccount(account, account.addr);
const algorand = AlgorandClient.mainNet().setDefaultSigner(signer);

src/types/algorand-client.ts:74


setDefaultValidityWindow(validityWindow): AlgorandClient

Sets the default validity window for transactions.

NameTypeDescription
validityWindownumber | bigintThe number of rounds between the first and last valid rounds

AlgorandClient

The AlgorandClient so method calls can be chained

Example

const algorand = AlgorandClient.mainNet().setDefaultValidityWindow(1000);

src/types/algorand-client.ts:59


setSigner(sender, signer): AlgorandClient

Tracks the given signer against the given sender for later signing.

NameTypeDescription
senderstring | AddressThe sender address to use this signer for
signerTransactionSignerThe signer to sign transactions with for the given sender

AlgorandClient

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);

src/types/algorand-client.ts:110


setSignerFromAccount(account): AlgorandClient

Tracks the given account (object that encapsulates an address and a signer) for later signing.

NameTypeDescription
accountMultisigAccount | default | SigningAccount | TransactionSignerAccount | LogicSigAccountThe account to register, which can be a TransactionSignerAccount or a algosdk.Account, algosdk.LogicSigAccount, SigningAccount or MultisigAccount

AlgorandClient

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 });

src/types/algorand-client.ts:94


setSuggestedParamsCache(suggestedParams, until?): AlgorandClient

Sets a cache value to use for suggested transaction params.

NameTypeDescription
suggestedParamsSuggestedParamsThe suggested params to use
until?DateA date until which to cache, or if not specified then the timeout is used

AlgorandClient

The AlgorandClient so method calls can be chained

Example

const algorand = AlgorandClient.mainNet().setSuggestedParamsCache(
suggestedParams,
new Date(+new Date() + 3_600_000),
);

src/types/algorand-client.ts:125


setSuggestedParamsCacheTimeout(timeout): AlgorandClient

Sets the timeout for caching suggested params.

NameTypeDescription
timeoutnumberThe timeout in milliseconds

AlgorandClient

The AlgorandClient so method calls can be chained

Example

const algorand = AlgorandClient.mainNet().setSuggestedParamsCacheTimeout(10_000);

src/types/algorand-client.ts:140


unregisterErrorTransformer(transformer): void

NameType
transformerErrorTransformer

void

src/types/algorand-client.ts:224


defaultLocalNet(): AlgorandClient

Creates an AlgorandClient pointing at default LocalNet ports and API token.

AlgorandClient

An instance of the AlgorandClient.

Example

const algorand = AlgorandClient.defaultLocalNet();

src/types/algorand-client.ts:281


fromClients(clients): AlgorandClient

Creates an AlgorandClient pointing to the given client(s).

NameTypeDescription
clientsAlgoSdkClientsThe clients to use.

AlgorandClient

An instance of the AlgorandClient.

Example

const algorand = AlgorandClient.fromClients({ algod, indexer, kmd });

src/types/algorand-client.ts:324


fromConfig(config): AlgorandClient

Creates an AlgorandClient from the given config.

NameTypeDescription
configAlgoConfigThe config to use.

AlgorandClient

An instance of the AlgorandClient.

Example

const client = AlgorandClient.fromConfig({ algodConfig, indexerConfig, kmdConfig });

src/types/algorand-client.ts:358


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.

AlgorandClient

An instance of the AlgorandClient.

Example

const client = AlgorandClient.fromEnvironment();

src/types/algorand-client.ts:347


mainNet(): AlgorandClient

Creates an AlgorandClient pointing at MainNet using AlgoNode.

AlgorandClient

An instance of the AlgorandClient.

Example

const algorand = AlgorandClient.mainNet();

src/types/algorand-client.ts:309


testNet(): AlgorandClient

Creates an AlgorandClient pointing at TestNet using AlgoNode.

AlgorandClient

An instance of the AlgorandClient.

Example

const algorand = AlgorandClient.testNet();

src/types/algorand-client.ts:295