Skip to content

TestNetDispenserApiClient

@algorandfoundation/algokit-utils / types/dispenser-client / TestNetDispenserApiClient

types/dispenser-client.TestNetDispenserApiClient

TestNetDispenserApiClient is a class that provides methods to interact with the Algorand TestNet Dispenser API. It allows you to fund an address with Algo, refund a transaction, and get the funding limit for the Algo asset.

The class requires an authentication token and a request timeout to be initialized. The authentication token can be provided either directly as a parameter or through an ALGOKIT_DISPENSER_ACCESS_TOKEN environment variable. If neither is provided, an error is thrown.

The request timeout can be provided as a parameter. If not provided, a default value is used.

Method

fund - Sends a funding request to the dispenser API to fund the specified address with the given amount of Algo.

Method

refund - Sends a refund request to the dispenser API for the specified refundTxnId.

Method

limit - Sends a request to the dispenser API to get the funding limit for the Algo asset.

Example

const client = new TestNetDispenserApiClient({ authToken: 'your_auth_token', requestTimeout: 30 });
const fundResponse = await client.fund('your_address', 100);
const limitResponse = await client.getLimit();
await client.refund('your_transaction_id');

Throws

If neither the environment variable ‘ALGOKIT_DISPENSER_ACCESS_TOKEN’ nor the authToken parameter were provided.

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new TestNetDispenserApiClient(params?): TestNetDispenserApiClient

Parameters

NameType
params?TestNetDispenserApiClientParams

Returns

TestNetDispenserApiClient

Defined in

src/types/dispenser-client.ts:76

Properties

_authToken

Private _authToken: string

Defined in

src/types/dispenser-client.ts:73


_requestTimeout

Private _requestTimeout: number

Defined in

src/types/dispenser-client.ts:74

Accessors

authToken

get authToken(): string

The authentication token used for API requests.

Returns

string

Defined in

src/types/dispenser-client.ts:92


requestTimeout

get requestTimeout(): number

The timeout for API requests, in seconds.

Returns

number

Defined in

src/types/dispenser-client.ts:96

Methods

fund

fund(address, amount): Promise<DispenserFundResponse>

Sends a funding request to the dispenser API to fund the specified address with the given amount of Algo.

Parameters

NameTypeDescription
addressstring | AddressThe address to fund.
amountnumber | bigintThe amount of µAlgo to fund.

Returns

Promise<DispenserFundResponse>

DispenserFundResponse: An object containing the transaction ID and funded amount.

Defined in

src/types/dispenser-client.ts:158


getLimit

getLimit(): Promise<DispenserLimitResponse>

Sends a request to the dispenser API to get the funding limit for the Algo asset.

Returns

Promise<DispenserLimitResponse>

DispenserLimitResponse: An object containing the funding limit amount.

Defined in

src/types/dispenser-client.ts:188


processDispenserRequest

processDispenserRequest(authToken, urlSuffix, body?, method?): Promise<Response>

Processes a dispenser API request.

Parameters

NameTypeDefault valueDescription
authTokenstringundefinedThe authentication token.
urlSuffixstringundefinedThe URL suffix for the API request.
bodynull | Record<string, string | number>nullThe request body.
methodstring'POST'The HTTP method.

Returns

Promise<Response>

The API response.

Defined in

src/types/dispenser-client.ts:110


refund

refund(refundTxnId): Promise<void>

Sends a refund request to the dispenser API for the specified refundTxnId.

Parameters

NameTypeDescription
refundTxnIdstringThe transaction ID to refund.

Returns

Promise<void>

Defined in

src/types/dispenser-client.ts:179