Skip to content

Commit 8731bfc

Browse files
committed
docs: align TS SDK guides with post-migration APT patterns
- Fetch Data: getAccountAPTAmount + generic getAccountResource example (en, zh) - First transaction: correct balance-check notes; zh uses aptos_account::transfer - Account abstraction: aptos_account::transfer; fix invalid new build.simple (en, zh)
1 parent c64b941 commit 8731bfc

File tree

6 files changed

+42
-31
lines changed

6 files changed

+42
-31
lines changed

src/content/docs/build/guides/first-transaction.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ This tutorial will guide you through creating and submitting your first transact
746746
```
747747

748748
<Aside type="note">
749-
Notice that Alice's balance decreased by more than 1000 octas. The extra amount is the gas fee paid to process the transaction. Behind the scenes, when checking balances, the SDK queries the CoinStore resource for the AptosCoin (`0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>`) and reads the current stored value. This demonstrates how the SDK abstracts away complex blockchain interactions into simple function calls.
749+
Notice that Alice's balance decreased by more than 1000 octas. The extra amount is the gas fee paid to process the transaction. When checking balances, the TypeScript SDK uses `getAccountAPTAmount`, which resolves APT after the Fungible Asset migration and does not rely on the legacy `CoinStore` resource (new accounts may not have it).
750750
</Aside>
751751
</Steps>
752752
</TabItem>
@@ -847,7 +847,7 @@ This tutorial will guide you through creating and submitting your first transact
847847
```
848848

849849
<Aside type="note">
850-
Notice that Alice's balance decreased by more than 1000 octas. The extra amount is the gas fee paid to process the transaction. Behind the scenes, when checking balances, the SDK queries the CoinStore resource for the AptosCoin (`0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>`) and reads the current stored value.
850+
Notice that Alice's balance decreased by more than 1000 octas. The extra amount is the gas fee paid to process the transaction. When checking balances, the Python SDK's `account_balance` uses the node's balance APIs, which reflect APT after the Fungible Asset migration rather than only the legacy `CoinStore` resource.
851851
</Aside>
852852
</Steps>
853853
</TabItem>

src/content/docs/build/sdks/ts-sdk/account/account-abstraction.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ const abstractedAccount = new AbstractedAccount({
248248
const coinTransferTransaction = await aptos.transaction.build.simple({
249249
sender: abstractedAccount.accountAddress,
250250
data: {
251-
function: "0x1::coin::transfer",
252-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
251+
function: "0x1::aptos_account::transfer",
253252
functionArguments: [alice.accountAddress, 100],
254253
},
255254
});
@@ -595,11 +594,10 @@ In this example, we will create an authenticator that allows users to permit cer
595594
is the same as the abstracted account's address.
596595

597596
```typescript
598-
const coinTransferTransaction = new aptos.transaction.build.simple({
597+
const coinTransferTransaction = await aptos.transaction.build.simple({
599598
sender: abstractedAccount.accountAddress,
600599
data: {
601-
function: "0x1::coin::transfer",
602-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
600+
function: "0x1::aptos_account::transfer",
603601
functionArguments: [alice.accountAddress, 100],
604602
},
605603
});

src/content/docs/build/sdks/ts-sdk/fetch-data-via-sdk.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,27 @@ The `Aptos` client can out of the box query both network data from [fullnodes](h
4242

4343
## Using Generic Queries
4444

45-
Some queries are intentionally broad, but this can make inferring the proper return type difficult. To accommodate that, these broad requests like `getAccountResources` allow you to specify what the expected response type should be.
45+
Some queries are intentionally broad, but this can make inferring the proper return type difficult. To accommodate that, broad requests like `getAccountResources` allow you to specify what the expected response type should be when you use `getAccountResource`.
46+
47+
After the [Fungible Asset migration](/build/smart-contracts/fungible-asset), use [`getAccountAPTAmount`](https://aptos-labs.github.io/aptos-ts-sdk/) for APT balances. New accounts may not publish the legacy `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>` resource, so reading it with `getAccountResource` can return "resource not found".
48+
49+
```typescript filename="fetch-data.ts"
50+
const aptAmount = await aptos.getAccountAPTAmount({
51+
accountAddress: testAccount.accountAddress,
52+
});
53+
```
54+
55+
For other on-chain resources, use `getAccountResource` with a generic type parameter:
4656

4757
```typescript filename="fetch-data.ts"
48-
type Coin = { coin: { value: string } };
58+
type OnChainAccount = { sequence_number: string; authentication_key: string };
4959

50-
const resource = await aptos.getAccountResource<Coin>({
60+
const accountResource = await aptos.getAccountResource<OnChainAccount>({
5161
accountAddress: testAccount.accountAddress,
52-
resourceType: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
62+
resourceType: "0x1::account::Account",
5363
});
5464

55-
// Now you have access to the response type property
56-
const value = resource.coin.value;
65+
const sequenceNumber = accountResource.sequence_number;
5766
```
5867

5968
## Using Move View Functions

src/content/docs/zh/build/guides/first-transaction.mdx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
137137
from aptos_sdk.account import Account
138138
from aptos_sdk.client import RestClient
139139
from aptos_sdk.transactions import EntryFunction, TransactionArgument, TransactionPayload
140-
from aptos_sdk.type_tag import TypeTag, StructTag
141140
```
142141
</TabItem>
143142
</Tabs>
@@ -237,8 +236,7 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
237236
const transaction = await aptos.transaction.build.simple({
238237
sender: alice.accountAddress,
239238
data: {
240-
function: "0x1::coin::transfer",
241-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
239+
function: "0x1::aptos_account::transfer",
242240
functionArguments: [bob.accountAddress, 1_000_000], // 0.01 APT
243241
},
244242
});
@@ -274,9 +272,9 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
274272
async def transfer_coins(alice, bob):
275273
# 构建交易
276274
payload = EntryFunction.natural(
277-
"0x1::coin",
275+
"0x1::aptos_account",
278276
"transfer",
279-
[TypeTag(StructTag.from_str("0x1::aptos_coin::AptosCoin"))],
277+
[],
280278
[
281279
TransactionArgument(bob.address(), "address"),
282280
TransactionArgument(1_000_000, "u64"), # 0.01 APT
@@ -388,8 +386,7 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
388386
const transaction = await aptos.transaction.build.simple({
389387
sender: alice.accountAddress,
390388
data: {
391-
function: "0x1::coin::transfer",
392-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
389+
function: "0x1::aptos_account::transfer",
393390
functionArguments: [bob.accountAddress, 1_000_000], // 0.01 APT
394391
},
395392
});

src/content/docs/zh/build/sdks/ts-sdk/account/account-abstraction.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ const abstractedAccount = new AbstractedAccount({
240240
const coinTransferTransaction = await aptos.transaction.build.simple({
241241
sender: abstractedAccount.accountAddress,
242242
data: {
243-
function: "0x1::coin::transfer",
244-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
243+
function: "0x1::aptos_account::transfer",
245244
functionArguments: [alice.accountAddress, 100],
246245
},
247246
});
@@ -577,11 +576,10 @@ const abstractedAccount = new AbstractedAccount({
577576
创建抽象账户后,我们可以正常使用它来签署交易.需要注意的是,交易中的 `sender` 字段必须与抽象账户地址一致.
578577

579578
```typescript
580-
const coinTransferTransaction = new aptos.transaction.build.simple({
579+
const coinTransferTransaction = await aptos.transaction.build.simple({
581580
sender: abstractedAccount.accountAddress,
582581
data: {
583-
function: "0x1::coin::transfer",
584-
typeArguments: ["0x1::aptos_coin::AptosCoin"],
582+
function: "0x1::aptos_account::transfer",
585583
functionArguments: [alice.accountAddress, 100],
586584
},
587585
});

src/content/docs/zh/build/sdks/ts-sdk/fetch-data-via-sdk.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,27 @@ const tokens = await aptos.getAccountOwnedTokens({ accountAddress: "0x123" });
4242

4343
## 使用通用查询
4444

45-
某些查询设计上是宽泛的,但这可能使得推断正确的返回类型变得困难.为了适应这种情况,像 `getAccountResources` 这样的广泛请求允许你指定预期的响应类型.
45+
某些查询设计上是宽泛的,但这可能使得推断正确的返回类型变得困难.为了适应这种情况,像 `getAccountResources` 这样的广泛请求允许你在使用 `getAccountResource` 时指定预期的响应类型.
46+
47+
[同质化资产迁移](/zh/build/smart-contracts/fungible-asset)之后,请使用 [`getAccountAPTAmount`](https://aptos-labs.github.io/aptos-ts-sdk/) 查询 APT 余额.新账户可能不会发布旧版 `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>` 资源,因此用 `getAccountResource` 读取它可能返回「资源未找到」.
48+
49+
```typescript filename="fetch-data.ts"
50+
const aptAmount = await aptos.getAccountAPTAmount({
51+
accountAddress: testAccount.accountAddress,
52+
});
53+
```
54+
55+
对于其他链上资源,可使用带泛型类型参数的 `getAccountResource`:
4656

4757
```typescript filename="fetch-data.ts"
48-
type Coin = { coin: { value: string } };
58+
type OnChainAccount = { sequence_number: string; authentication_key: string };
4959

50-
const resource = await aptos.getAccountResource<Coin>({
60+
const accountResource = await aptos.getAccountResource<OnChainAccount>({
5161
accountAddress: testAccount.accountAddress,
52-
resourceType: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
62+
resourceType: "0x1::account::Account",
5363
});
5464

55-
// 现在你可以访问响应类型属性
56-
const value = resource.coin.value;
65+
const sequenceNumber = accountResource.sequence_number;
5766
```
5867

5968
## 使用 Move 视图函数

0 commit comments

Comments
 (0)