Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Faucet] Add integrator's guide #7293

Merged
merged 4 commits into from
Mar 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions developer-docs-site/docs/guides/system-integrators-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ JSON-encoded transactions allow for rapid development and support seamless ABI c

### Types of transactions

Within a given transaction, the target of execution can be one of two types:
Within a given transaction, the target of execution can be one of two types:

- An entry point (formerly known as script function)
- A script (payload)

Both [Python](https://github.com/aptos-labs/aptos-core/blob/3973311dac6bb9348bfc81cf983c2a1be11f1b48/ecosystem/python/sdk/aptos_sdk/client.py#L256) and [TypeScript](https://github.com/aptos-labs/aptos-core/blob/3973311dac6bb9348bfc81cf983c2a1be11f1b48/ecosystem/typescript/sdk/src/aptos_client.test.ts#L93) support the generation of transactions that target entry points. This guide points out many of those entry points, such as `aptos_account::transfer` and `aptos_account::create_account`.
Both [Python](https://github.com/aptos-labs/aptos-core/blob/3973311dac6bb9348bfc81cf983c2a1be11f1b48/ecosystem/python/sdk/aptos_sdk/client.py#L256) and [TypeScript](https://github.com/aptos-labs/aptos-core/blob/3973311dac6bb9348bfc81cf983c2a1be11f1b48/ecosystem/typescript/sdk/src/aptos_client.test.ts#L93) support the generation of transactions that target entry points. This guide points out many of those entry points, such as `aptos_account::transfer` and `aptos_account::create_account`.

Most basic operations on the Aptos blockchain should be available via entry point calls. While one could submit multiple transactions calling entry points in series, such operations benefit from being called atomically from a single transaction. A script payload transaction can call any public (entry) function defined within any module. Here's an example [Move script](https://github.com/aptos-labs/aptos-core/tree/main/aptos-move/move-examples/scripts/two_by_two_transfer) that uses a MultiAgent transaction to extract funds from two accounts and deposit them into two other accounts. This is a [Python example](https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/examples/transfer-two-by-two.py) that uses the bytecode generated by compiling that script. Currently there is limited support for script payloads in TypeScript.

Expand All @@ -162,12 +162,12 @@ Most integrations into the Aptos blockchain benefit from a holistic and comprehe
* The state is the representation of all transaction outputs up to a specific version. In other words, a state version is the accumulation of all transactions inclusive of that transaction version.
* As transactions execute, they may emit events. [Events](../concepts/events.md) are hints about changes in on-chain data.

The storage service on a node employs two forms of pruning that erase data from nodes:
The storage service on a node employs two forms of pruning that erase data from nodes:

* state
* events, transactions, and everything else

While either of these may be disabled, storing the state versions is not particularly sustainable.
While either of these may be disabled, storing the state versions is not particularly sustainable.

Events and transactions pruning can be disabled via setting the [`enable_ledger_pruner`](https://github.com/aptos-labs/aptos-core/blob/cf0bc2e4031a843cdc0c04e70b3f7cd92666afcf/config/src/config/storage_config.rs#L141) to `false`. This is default behavior in Mainnet. In the near future, Aptos will provide indexers that mitigate the need to directly query from a node.

Expand All @@ -179,13 +179,13 @@ The REST API offers querying transactions and events in these ways:

## Exchanging and tracking coins

Aptos has a standard [Coin type](https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/coin.move). Different types of coins can be represented in this type through the use of distinct structs that represent the type parameter or generic for `Coin<T>`.
Aptos has a standard [Coin type](https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/framework/aptos-framework/sources/coin.move). Different types of coins can be represented in this type through the use of distinct structs that represent the type parameter or generic for `Coin<T>`.

Coins are stored within an account under the resource `CoinStore<T>`. At account creation, each user has the resource `CoinStore<0x1::aptos_coin::AptosCoin>` or `CoinStore<AptosCoin>`, for short. Within this resource is the Aptos coin: `Coin<AptosCoin>`.

### Transferring coins between users

Coins can be transferred between users via the [`coin::transfer`](https://github.com/aptos-labs/aptos-core/blob/36a7c00b29a457469264187d8e44070b2d5391fe/aptos-move/framework/aptos-framework/sources/coin.move#L307) function for all coins and [`aptos_account::transfer`](https://github.com/aptos-labs/aptos-core/blob/88c9aab3982c246f8aa75eb2caf8c8ab1dcab491/aptos-move/framework/aptos-framework/sources/aptos_account.move#L18) for Aptos coins. The advantage of the latter function is that it creates the destination account if it does not exist.
Coins can be transferred between users via the [`coin::transfer`](https://github.com/aptos-labs/aptos-core/blob/36a7c00b29a457469264187d8e44070b2d5391fe/aptos-move/framework/aptos-framework/sources/coin.move#L307) function for all coins and [`aptos_account::transfer`](https://github.com/aptos-labs/aptos-core/blob/88c9aab3982c246f8aa75eb2caf8c8ab1dcab491/aptos-move/framework/aptos-framework/sources/aptos_account.move#L18) for Aptos coins. The advantage of the latter function is that it creates the destination account if it does not exist.

:::caution
It is important to note that if an account has not registered a `CoinStore<T>` for a given `T`, then any transfer of type `T` to that account will fail.
Expand Down Expand Up @@ -499,3 +499,47 @@ By monitoring the events, you will find all balance changes in the `0x1::coin::C
To create some sample data to explore, conduct ["Your first transaction"](../tutorials/first-transaction.md).

To learn more about coin creation, make ["Your First Coin"](../tutorials/first-coin.md).

## Integrating with the faucet

This explains how to integrate with the [Aptos Faucet](https://github.com/aptos-labs/aptos-core/tree/main/crates/aptos-faucet). This is targeted at SDK and wallet creators; if you are a developer using either of these tools, access the faucet through the SDK / wallet instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this reference confusing and am not sure yet how to fix it?
"This is targeted at SDK and wallet creators; if you are a developer using either of these tools, access the faucet through the SDK / wallet instead."

We are saying these instructions are for SDK and wallet folks and then if you are using those tools to do something else instead?

What is the instead for? Sorry if I am being dense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same question, @banool. Please clarify if you meant something like "This tutorial explains how SDK and wallet creators can integrate with the Aptos Faucet. If you are a dapp developer, access the faucet through an existing SDK or wallet instead."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I agree it is a bit confusing. So this guide is intended for people building developer libraries / tools (SDKs / wallets). For example, in the TS SDK we provide functions to let people call the faucet. In this case, the target audience is SDK devs, like us or whoever out there is making SDKs in other languages. For wallets, they usually want to provide a "use faucet" button, so they need to know how to use the faucet (though in that case, they might just use an SDK). So in this case the relevant people are the wallet creators. So the target audience is SDK / wallet devs. Notably this means this guide is not relevant for dapp devs, because they should just invoke the faucet via the wallet / SDK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to make whatever changes you think make this clearer and I can take a look!

Copy link
Contributor

@davidiw davidiw Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please let's address this before landing. @clay-aptos , @saharct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@banool I rewrote that portion. Please review it and let me know if any changes are needed. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks a lot!


### Differences between devnet and testnet
What are the differences between devnet and testnet? Effectively none. In the past, the testnet faucet had a Captcha in front of it, making it unqueryable by normal means. This is no longer true.

The endpoints for each faucet are:
- Devnet: https://faucet.devnet.aptoslabs.com
- Testnet: https://faucet.testnet.aptoslabs.com

### Calling the faucet: JavaScript / TypeScript
If you are building a client in JavaScript or TypeScript, you should make use of the [@aptos-labs/aptos-faucet-client](https://www.npmjs.com/package/@aptos-labs/aptos-faucet-client) package. This client is generated based on the OpenAPI spec published by the faucet service.

Example use:
```typescript
import {
AptosFaucetClient,
FundRequest,
} from "@aptos-labs/aptos-faucet-client";

async function callFaucet(amount: number, address: string): Promise<string[]> {
const faucetClient = new AptosFaucetClient({BASE: "https://faucet.devnet.aptoslabs.com"});
const request: FundRequest = {
amount,
address,
};
const response = await faucetClient.fund.fund({ requestBody: request });
return response.txn_hashes;
}
```

### Calling the faucet: Other languages
If you are trying to call the faucet in other languages, you have two options:
1. Generate a client from the [OpenAPI spec](https://github.com/aptos-labs/aptos-core/blob/main/crates/aptos-faucet/doc/spec.yaml).
2. Call the faucet on your own.

For the latter, you will want to build a query similar to this:
```
curl -X POST 'https://faucet.devnet.aptoslabs.com/mint?amount=10000&address=0xd0f523c9e73e6f3d68c16ae883a9febc616e484c4998a72d8899a1009e5a89d6'
```

This means mint 10000 OCTA to address `0xd0f523c9e73e6f3d68c16ae883a9febc616e484c4998a72d8899a1009e5a89d6`.