Skip to content

Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

types dispenser client.TestNetDispenserApiClient

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

Class: 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 Algos, 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
Name Type
params null | TestNetDispenserApiClientParams
Returns

TestNetDispenserApiClient

Defined in

src/types/dispenser-client.ts:61

Properties

_authToken

Private _authToken: string

Defined in

src/types/dispenser-client.ts:58


_requestTimeout

Private _requestTimeout: number

Defined in

src/types/dispenser-client.ts:59

Accessors

authToken

get authToken(): string

The authentication token used for API requests.

Returns

string

Defined in

src/types/dispenser-client.ts:77


requestTimeout

get requestTimeout(): number

The timeout for API requests, in seconds.

Returns

number

Defined in

src/types/dispenser-client.ts:81

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
Name Type Description
address string The address to fund.
amount number The 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:142


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:168


processDispenserRequest

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

Processes a dispenser API request.

Parameters
Name Type Default value Description
authToken string undefined The authentication token.
urlSuffix string undefined The URL suffix for the API request.
body null | Record\<string, string | number> null The request body.
method string 'POST' The HTTP method.
Returns

Promise\<Response>

The API response.

Defined in

src/types/dispenser-client.ts:95


refund

refund(refundTxnId): Promise\<void>

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

Parameters
Name Type Description
refundTxnId string The transaction ID to refund.
Returns

Promise\<void>

Defined in

src/types/dispenser-client.ts:159