-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,037 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## Proposed Changes | ||
|
||
- | ||
- | ||
- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# TestNet Dispenser Client | ||
|
||
The TestNet Dispenser Client is a utility for interacting with the AlgoKit TestNet Dispenser API. It provides methods to fund an account, register a refund for a transaction, and get the current limit for an account. | ||
|
||
## Creating a Dispenser Client | ||
|
||
To create a Dispenser Client, you need to provide an authorization token. This can be done in two ways: | ||
|
||
1. Pass the token directly to the client constructor as `authToken`. | ||
2. Set the token as an environment variable `ALGOKIT_DISPENSER_ACCESS_TOKEN` (see [docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md#error-handling) on how to obtain the token). | ||
|
||
If both methods are used, the constructor argument takes precedence. | ||
|
||
```ts | ||
import * as algokit from '@algorandfoundation/algokit-utils' | ||
|
||
// Using constructor argument | ||
const client = algokit.getTestNetDispenserApiClient({ authToken: 'your_auth_token' }) | ||
|
||
// Using environment variable | ||
process.env['ALGOKIT_DISPENSER_ACCESS_TOKEN'] = 'your_auth_token' | ||
const client = algokit.getTestNetDispenserApiClient() | ||
``` | ||
|
||
## Funding an Account | ||
|
||
To fund an account with Algos from the dispenser API, use the `fund` method. This method requires the receiver's address, the amount to be funded, and the asset ID. | ||
|
||
```ts | ||
const response = await client.fund('receiver_address', 1000) | ||
``` | ||
|
||
The `fund` method returns a `DispenserFundResponse` object, which contains the transaction ID (`txId`) and the amount funded. | ||
|
||
## Registering a Refund | ||
|
||
To register a refund for a transaction with the dispenser API, use the `refund` method. This method requires the transaction ID of the refund transaction. | ||
|
||
```ts | ||
await client.refund('transaction_id') | ||
``` | ||
|
||
> Keep in mind, to perform a refund you need to perform a payment transaction yourself first by sending funds back to TestNet Dispenser, then you can invoke this refund endpoint and pass the txn_id of your refund txn. You can obtain dispenser address by inspecting the sender field of any issued fund transaction initiated via [fund](#funding-an-account). | ||
## Getting Current Limit | ||
|
||
To get the current limit for an account with Algos from the dispenser API, use the `getLimit` method. This method requires the account address. | ||
|
||
```ts | ||
const response = await client.getLimit() | ||
``` | ||
|
||
The `limit` method returns a `DispenserLimitResponse` object, which contains the current limit amount. | ||
|
||
## Error Handling | ||
|
||
If an error occurs while making a request to the dispenser API, an exception will be raised with a message indicating the type of error. Refer to [Error Handling docs](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md#error-handling) for details on how you can handle each individual error `code`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 221 additions & 0 deletions
221
docs/code/classes/types_dispenser_client.TestNetDispenserApiClient.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
[@algorandfoundation/algokit-utils](../README.md) / [types/dispenser-client](../modules/types_dispenser_client.md) / TestNetDispenserApiClient | ||
|
||
# Class: TestNetDispenserApiClient | ||
|
||
[types/dispenser-client](../modules/types_dispenser_client.md).TestNetDispenserApiClient | ||
|
||
`TestNetDispenserApiClient` is a class that provides methods to interact with the [Algorand TestNet Dispenser API](https://github.com/algorandfoundation/algokit/blob/main/docs/testnet_api.md). | ||
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`** | ||
|
||
```typescript | ||
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 | ||
|
||
- [constructor](types_dispenser_client.TestNetDispenserApiClient.md#constructor) | ||
|
||
### Properties | ||
|
||
- [\_authToken](types_dispenser_client.TestNetDispenserApiClient.md#_authtoken) | ||
- [\_requestTimeout](types_dispenser_client.TestNetDispenserApiClient.md#_requesttimeout) | ||
|
||
### Accessors | ||
|
||
- [authToken](types_dispenser_client.TestNetDispenserApiClient.md#authtoken) | ||
- [requestTimeout](types_dispenser_client.TestNetDispenserApiClient.md#requesttimeout) | ||
|
||
### Methods | ||
|
||
- [fund](types_dispenser_client.TestNetDispenserApiClient.md#fund) | ||
- [getLimit](types_dispenser_client.TestNetDispenserApiClient.md#getlimit) | ||
- [processDispenserRequest](types_dispenser_client.TestNetDispenserApiClient.md#processdispenserrequest) | ||
- [refund](types_dispenser_client.TestNetDispenserApiClient.md#refund) | ||
|
||
## Constructors | ||
|
||
### constructor | ||
|
||
• **new TestNetDispenserApiClient**(`params`) | ||
|
||
#### Parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `params` | ``null`` \| [`TestNetDispenserApiClientParams`](../interfaces/types_dispenser_client.TestNetDispenserApiClientParams.md) | | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:63](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L63) | ||
|
||
## Properties | ||
|
||
### \_authToken | ||
|
||
• `Private` **\_authToken**: `string` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:60](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L60) | ||
|
||
___ | ||
|
||
### \_requestTimeout | ||
|
||
• `Private` **\_requestTimeout**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:61](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L61) | ||
|
||
## Accessors | ||
|
||
### authToken | ||
|
||
• `get` **authToken**(): `string` | ||
|
||
The authentication token used for API requests. | ||
|
||
#### Returns | ||
|
||
`string` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:79](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L79) | ||
|
||
___ | ||
|
||
### requestTimeout | ||
|
||
• `get` **requestTimeout**(): `number` | ||
|
||
The timeout for API requests, in seconds. | ||
|
||
#### Returns | ||
|
||
`number` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:83](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L83) | ||
|
||
## Methods | ||
|
||
### fund | ||
|
||
▸ **fund**(`address`, `amount`): `Promise`<[`DispenserFundResponse`](../interfaces/types_dispenser_client.DispenserFundResponse.md)\> | ||
|
||
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`](../interfaces/types_dispenser_client.DispenserFundResponse.md)\> | ||
|
||
DispenserFundResponse: An object containing the transaction ID and funded amount. | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:144](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L144) | ||
|
||
___ | ||
|
||
### getLimit | ||
|
||
▸ **getLimit**(): `Promise`<[`DispenserLimitResponse`](../interfaces/types_dispenser_client.DispenserLimitResponse.md)\> | ||
|
||
Sends a request to the dispenser API to get the funding limit for the Algo asset. | ||
|
||
#### Returns | ||
|
||
`Promise`<[`DispenserLimitResponse`](../interfaces/types_dispenser_client.DispenserLimitResponse.md)\> | ||
|
||
DispenserLimitResponse: An object containing the funding limit amount. | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:170](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L170) | ||
|
||
___ | ||
|
||
### processDispenserRequest | ||
|
||
▸ `Private` **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:97](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L97) | ||
|
||
___ | ||
|
||
### 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:161](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L161) |
32 changes: 32 additions & 0 deletions
32
docs/code/interfaces/types_dispenser_client.DispenserFundResponse.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[@algorandfoundation/algokit-utils](../README.md) / [types/dispenser-client](../modules/types_dispenser_client.md) / DispenserFundResponse | ||
|
||
# Interface: DispenserFundResponse | ||
|
||
[types/dispenser-client](../modules/types_dispenser_client.md).DispenserFundResponse | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [amount](types_dispenser_client.DispenserFundResponse.md#amount) | ||
- [txId](types_dispenser_client.DispenserFundResponse.md#txid) | ||
|
||
## Properties | ||
|
||
### amount | ||
|
||
• **amount**: `number` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:21](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L21) | ||
|
||
___ | ||
|
||
### txId | ||
|
||
• **txId**: `string` | ||
|
||
#### Defined in | ||
|
||
[src/types/dispenser-client.ts:20](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/dispenser-client.ts#L20) |
Oops, something went wrong.