diff --git a/src/content/docs/build/guides/first-transaction.mdx b/src/content/docs/build/guides/first-transaction.mdx
index 73988111..a54bbee1 100644
--- a/src/content/docs/build/guides/first-transaction.mdx
+++ b/src/content/docs/build/guides/first-transaction.mdx
@@ -746,7 +746,7 @@ This tutorial will guide you through creating and submitting your first transact
```
@@ -847,7 +847,7 @@ This tutorial will guide you through creating and submitting your first transact
```
diff --git a/src/content/docs/build/sdks/ts-sdk/account/account-abstraction.mdx b/src/content/docs/build/sdks/ts-sdk/account/account-abstraction.mdx
index ffb2217e..11706819 100644
--- a/src/content/docs/build/sdks/ts-sdk/account/account-abstraction.mdx
+++ b/src/content/docs/build/sdks/ts-sdk/account/account-abstraction.mdx
@@ -248,8 +248,7 @@ const abstractedAccount = new AbstractedAccount({
const coinTransferTransaction = await aptos.transaction.build.simple({
sender: abstractedAccount.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [alice.accountAddress, 100],
},
});
@@ -595,11 +594,10 @@ In this example, we will create an authenticator that allows users to permit cer
is the same as the abstracted account's address.
```typescript
- const coinTransferTransaction = new aptos.transaction.build.simple({
+ const coinTransferTransaction = await aptos.transaction.build.simple({
sender: abstractedAccount.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [alice.accountAddress, 100],
},
});
diff --git a/src/content/docs/build/sdks/ts-sdk/fetch-data-via-sdk.mdx b/src/content/docs/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
index 21ec1198..ce75732f 100644
--- a/src/content/docs/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
+++ b/src/content/docs/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
@@ -42,18 +42,27 @@ The `Aptos` client can out of the box query both network data from [fullnodes](h
## Using Generic Queries
-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.
+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`.
+
+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".
+
+```typescript filename="fetch-data.ts"
+const aptAmount = await aptos.getAccountAPTAmount({
+ accountAddress: testAccount.accountAddress,
+});
+```
+
+For other on-chain resources, use `getAccountResource` with a generic type parameter:
```typescript filename="fetch-data.ts"
-type Coin = { coin: { value: string } };
+type OnChainAccount = { sequence_number: string; authentication_key: string };
-const resource = await aptos.getAccountResource({
+const accountResource = await aptos.getAccountResource({
accountAddress: testAccount.accountAddress,
- resourceType: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
+ resourceType: "0x1::account::Account",
});
-// Now you have access to the response type property
-const value = resource.coin.value;
+const sequenceNumber = accountResource.sequence_number;
```
## Using Move View Functions
diff --git a/src/content/docs/build/sdks/ts-sdk/quickstart.mdx b/src/content/docs/build/sdks/ts-sdk/quickstart.mdx
index 44f49d98..c9db82d3 100644
--- a/src/content/docs/build/sdks/ts-sdk/quickstart.mdx
+++ b/src/content/docs/build/sdks/ts-sdk/quickstart.mdx
@@ -159,6 +159,8 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
function: "0x1::aptos_account::transfer",
functionArguments: [bob.accountAddress, 100],
},
+ // Lower default gas fits typical devnet faucet funding (1 APT)
+ options: { maxGasAmount: 100_000 },
});
...
```
@@ -229,8 +231,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
-const APTOS_COIN = "0x1::aptos_coin::AptosCoin";
-const COIN_STORE = `0x1::coin::CoinStore<${APTOS_COIN}>`;
const ALICE_INITIAL_BALANCE = 100_000_000;
const BOB_INITIAL_BALANCE = 100;
const TRANSFER_AMOUNT = 100;
@@ -267,20 +267,17 @@ async function example() {
});
console.log("Alice and Bob's accounts have been funded!");
- // Look up the newly funded account's balances
+ // Look up the newly funded account's balances (uses Fungible Asset balance APIs;
+ // legacy CoinStore resources may be absent on new accounts)
console.log("\n=== Balances ===\n");
- const aliceAccountBalance = await aptos.getAccountResource({
+ const aliceBalance = await aptos.getAccountAPTAmount({
accountAddress: alice.accountAddress,
- resourceType: COIN_STORE,
});
- const aliceBalance = Number(aliceAccountBalance.coin.value);
console.log(`Alice's balance is: ${aliceBalance}`);
- const bobAccountBalance = await aptos.getAccountResource({
+ const bobBalance = await aptos.getAccountAPTAmount({
accountAddress: bob.accountAddress,
- resourceType: COIN_STORE,
});
- const bobBalance = Number(bobAccountBalance.coin.value);
console.log(`Bob's balance is: ${bobBalance}`);
// Send a transaction from Alice's account to Bob's account
@@ -289,8 +286,9 @@ async function example() {
data: {
// All transactions on Aptos are implemented via smart contracts.
function: "0x1::aptos_account::transfer",
- functionArguments: [bob.accountAddress, 100],
+ functionArguments: [bob.accountAddress, TRANSFER_AMOUNT],
},
+ options: { maxGasAmount: 100_000 },
});
console.log("\n=== Transfer transaction ===\n");
@@ -306,18 +304,14 @@ async function example() {
console.log("Transaction hash:", executedTransaction.hash);
console.log("\n=== Balances after transfer ===\n");
- const newAliceAccountBalance = await aptos.getAccountResource({
+ const newAliceBalance = await aptos.getAccountAPTAmount({
accountAddress: alice.accountAddress,
- resourceType: COIN_STORE,
});
- const newAliceBalance = Number(newAliceAccountBalance.coin.value);
console.log(`Alice's balance is: ${newAliceBalance}`);
- const newBobAccountBalance = await aptos.getAccountResource({
+ const newBobBalance = await aptos.getAccountAPTAmount({
accountAddress: bob.accountAddress,
- resourceType: COIN_STORE,
});
- const newBobBalance = Number(newBobAccountBalance.coin.value);
console.log(`Bob's balance is: ${newBobBalance}`);
// Bob should have the transfer amount
diff --git a/src/content/docs/zh/build/guides/first-transaction.mdx b/src/content/docs/zh/build/guides/first-transaction.mdx
index 1d416544..8ade70cb 100644
--- a/src/content/docs/zh/build/guides/first-transaction.mdx
+++ b/src/content/docs/zh/build/guides/first-transaction.mdx
@@ -137,7 +137,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
from aptos_sdk.account import Account
from aptos_sdk.client import RestClient
from aptos_sdk.transactions import EntryFunction, TransactionArgument, TransactionPayload
- from aptos_sdk.type_tag import TypeTag, StructTag
```
@@ -237,8 +236,7 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
const transaction = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [bob.accountAddress, 1_000_000], // 0.01 APT
},
});
@@ -274,9 +272,9 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
async def transfer_coins(alice, bob):
# 构建交易
payload = EntryFunction.natural(
- "0x1::coin",
+ "0x1::aptos_account",
"transfer",
- [TypeTag(StructTag.from_str("0x1::aptos_coin::AptosCoin"))],
+ [],
[
TransactionArgument(bob.address(), "address"),
TransactionArgument(1_000_000, "u64"), # 0.01 APT
@@ -388,8 +386,7 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
const transaction = await aptos.transaction.build.simple({
sender: alice.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [bob.accountAddress, 1_000_000], // 0.01 APT
},
});
diff --git a/src/content/docs/zh/build/sdks/ts-sdk/account/account-abstraction.mdx b/src/content/docs/zh/build/sdks/ts-sdk/account/account-abstraction.mdx
index 0ebdb385..b59b58e5 100644
--- a/src/content/docs/zh/build/sdks/ts-sdk/account/account-abstraction.mdx
+++ b/src/content/docs/zh/build/sdks/ts-sdk/account/account-abstraction.mdx
@@ -240,8 +240,7 @@ const abstractedAccount = new AbstractedAccount({
const coinTransferTransaction = await aptos.transaction.build.simple({
sender: abstractedAccount.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [alice.accountAddress, 100],
},
});
@@ -577,11 +576,10 @@ const abstractedAccount = new AbstractedAccount({
创建抽象账户后,我们可以正常使用它来签署交易.需要注意的是,交易中的 `sender` 字段必须与抽象账户地址一致.
```typescript
- const coinTransferTransaction = new aptos.transaction.build.simple({
+ const coinTransferTransaction = await aptos.transaction.build.simple({
sender: abstractedAccount.accountAddress,
data: {
- function: "0x1::coin::transfer",
- typeArguments: ["0x1::aptos_coin::AptosCoin"],
+ function: "0x1::aptos_account::transfer",
functionArguments: [alice.accountAddress, 100],
},
});
diff --git a/src/content/docs/zh/build/sdks/ts-sdk/fetch-data-via-sdk.mdx b/src/content/docs/zh/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
index 9b51432d..6a2b8bac 100644
--- a/src/content/docs/zh/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
+++ b/src/content/docs/zh/build/sdks/ts-sdk/fetch-data-via-sdk.mdx
@@ -42,18 +42,27 @@ const tokens = await aptos.getAccountOwnedTokens({ accountAddress: "0x123" });
## 使用通用查询
-某些查询设计上是宽泛的,但这可能使得推断正确的返回类型变得困难.为了适应这种情况,像 `getAccountResources` 这样的广泛请求允许你指定预期的响应类型.
+某些查询设计上是宽泛的,但这可能使得推断正确的返回类型变得困难.为了适应这种情况,像 `getAccountResources` 这样的广泛请求允许你在使用 `getAccountResource` 时指定预期的响应类型.
+
+在[同质化资产迁移](/zh/build/smart-contracts/fungible-asset)之后,请使用 [`getAccountAPTAmount`](https://aptos-labs.github.io/aptos-ts-sdk/) 查询 APT 余额.新账户可能不会发布旧版 `0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>` 资源,因此用 `getAccountResource` 读取它可能返回「资源未找到」.
+
+```typescript filename="fetch-data.ts"
+const aptAmount = await aptos.getAccountAPTAmount({
+ accountAddress: testAccount.accountAddress,
+});
+```
+
+对于其他链上资源,可使用带泛型类型参数的 `getAccountResource`:
```typescript filename="fetch-data.ts"
-type Coin = { coin: { value: string } };
+type OnChainAccount = { sequence_number: string; authentication_key: string };
-const resource = await aptos.getAccountResource({
+const accountResource = await aptos.getAccountResource({
accountAddress: testAccount.accountAddress,
- resourceType: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
+ resourceType: "0x1::account::Account",
});
-// 现在你可以访问响应类型属性
-const value = resource.coin.value;
+const sequenceNumber = accountResource.sequence_number;
```
## 使用 Move 视图函数
diff --git a/src/content/docs/zh/build/sdks/ts-sdk/quickstart.mdx b/src/content/docs/zh/build/sdks/ts-sdk/quickstart.mdx
index cf3e8b41..05256eb6 100644
--- a/src/content/docs/zh/build/sdks/ts-sdk/quickstart.mdx
+++ b/src/content/docs/zh/build/sdks/ts-sdk/quickstart.mdx
@@ -155,6 +155,8 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
function: "0x1::aptos_account::transfer",
functionArguments: [bob.accountAddress, 100],
},
+ // 降低默认 gas 上限以适配常见 devnet 水龙头额度(1 APT)
+ options: { maxGasAmount: 100_000 },
});
...
```
@@ -225,8 +227,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
-const APTOS_COIN = "0x1::aptos_coin::AptosCoin";
-const COIN_STORE = `0x1::coin::CoinStore<${APTOS_COIN}>`;
const ALICE_INITIAL_BALANCE = 100_000_000;
const BOB_INITIAL_BALANCE = 100;
const TRANSFER_AMOUNT = 100;
@@ -263,20 +263,16 @@ async function example() {
});
console.log("Alice 和 Bob 的账户已成功注资!");
- // 查询新注资账户的余额
+ // 查询新注资账户的余额(使用同质化资产余额接口;新账户可能没有旧版 CoinStore 资源)
console.log("\n=== 余额 ===\n");
- const aliceAccountBalance = await aptos.getAccountResource({
+ const aliceBalance = await aptos.getAccountAPTAmount({
accountAddress: alice.accountAddress,
- resourceType: COIN_STORE,
});
- const aliceBalance = Number(aliceAccountBalance.coin.value);
console.log(`Alice 的余额是: ${aliceBalance}`);
- const bobAccountBalance = await aptos.getAccountResource({
+ const bobBalance = await aptos.getAccountAPTAmount({
accountAddress: bob.accountAddress,
- resourceType: COIN_STORE,
});
- const bobBalance = Number(bobAccountBalance.coin.value);
console.log(`Bob 的余额是: ${bobBalance}`);
// 从 Alice 账户向 Bob 账户发送交易
@@ -285,8 +281,9 @@ async function example() {
data: {
// Aptos 上的所有交易都是通过智能合约实现的。
function: "0x1::aptos_account::transfer",
- functionArguments: [bob.accountAddress, 100],
+ functionArguments: [bob.accountAddress, TRANSFER_AMOUNT],
},
+ options: { maxGasAmount: 100_000 },
});
console.log("\n=== 转账交易 ===\n");
@@ -299,19 +296,16 @@ async function example() {
const executedTransaction = await aptos.waitForTransaction({
transactionHash: committedTxn.hash,
});
- console.log("交易哈希:", executedTransaction.hash); console.log("\n=== 转账后余额 ===\n");
- const newAliceAccountBalance = await aptos.getAccountResource({
+ console.log("交易哈希:", executedTransaction.hash);
+ console.log("\n=== 转账后余额 ===\n");
+ const newAliceBalance = await aptos.getAccountAPTAmount({
accountAddress: alice.accountAddress,
- resourceType: COIN_STORE,
});
- const newAliceBalance = Number(newAliceAccountBalance.coin.value);
console.log(`Alice 的余额是: ${newAliceBalance}`);
- const newBobAccountBalance = await aptos.getAccountResource({
+ const newBobBalance = await aptos.getAccountAPTAmount({
accountAddress: bob.accountAddress,
- resourceType: COIN_STORE,
});
- const newBobBalance = Number(newBobAccountBalance.coin.value);
console.log(`Bob 的余额是: ${newBobBalance}`);
// Bob 应该收到转账金额