Skip to content

Commit c64b941

Browse files
committed
docs: update TS SDK quickstart for FA balance APIs
- Use getAccountAPTAmount instead of getAccountResource(CoinStore) - Add maxGasAmount for devnet faucet compatibility - Match aptos-ts-sdk PR #852 patterns (en + zh)
1 parent 3933f14 commit c64b941

File tree

2 files changed

+21
-33
lines changed

2 files changed

+21
-33
lines changed

src/content/docs/build/sdks/ts-sdk/quickstart.mdx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
159159
function: "0x1::aptos_account::transfer",
160160
functionArguments: [bob.accountAddress, 100],
161161
},
162+
// Lower default gas fits typical devnet faucet funding (1 APT)
163+
options: { maxGasAmount: 100_000 },
162164
});
163165
...
164166
```
@@ -229,8 +231,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
229231

230232
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
231233

232-
const APTOS_COIN = "0x1::aptos_coin::AptosCoin";
233-
const COIN_STORE = `0x1::coin::CoinStore<${APTOS_COIN}>`;
234234
const ALICE_INITIAL_BALANCE = 100_000_000;
235235
const BOB_INITIAL_BALANCE = 100;
236236
const TRANSFER_AMOUNT = 100;
@@ -267,20 +267,17 @@ async function example() {
267267
});
268268
console.log("Alice and Bob's accounts have been funded!");
269269

270-
// Look up the newly funded account's balances
270+
// Look up the newly funded account's balances (uses Fungible Asset balance APIs;
271+
// legacy CoinStore resources may be absent on new accounts)
271272
console.log("\n=== Balances ===\n");
272-
const aliceAccountBalance = await aptos.getAccountResource({
273+
const aliceBalance = await aptos.getAccountAPTAmount({
273274
accountAddress: alice.accountAddress,
274-
resourceType: COIN_STORE,
275275
});
276-
const aliceBalance = Number(aliceAccountBalance.coin.value);
277276
console.log(`Alice's balance is: ${aliceBalance}`);
278277

279-
const bobAccountBalance = await aptos.getAccountResource({
278+
const bobBalance = await aptos.getAccountAPTAmount({
280279
accountAddress: bob.accountAddress,
281-
resourceType: COIN_STORE,
282280
});
283-
const bobBalance = Number(bobAccountBalance.coin.value);
284281
console.log(`Bob's balance is: ${bobBalance}`);
285282

286283
// Send a transaction from Alice's account to Bob's account
@@ -289,8 +286,9 @@ async function example() {
289286
data: {
290287
// All transactions on Aptos are implemented via smart contracts.
291288
function: "0x1::aptos_account::transfer",
292-
functionArguments: [bob.accountAddress, 100],
289+
functionArguments: [bob.accountAddress, TRANSFER_AMOUNT],
293290
},
291+
options: { maxGasAmount: 100_000 },
294292
});
295293

296294
console.log("\n=== Transfer transaction ===\n");
@@ -306,18 +304,14 @@ async function example() {
306304
console.log("Transaction hash:", executedTransaction.hash);
307305

308306
console.log("\n=== Balances after transfer ===\n");
309-
const newAliceAccountBalance = await aptos.getAccountResource({
307+
const newAliceBalance = await aptos.getAccountAPTAmount({
310308
accountAddress: alice.accountAddress,
311-
resourceType: COIN_STORE,
312309
});
313-
const newAliceBalance = Number(newAliceAccountBalance.coin.value);
314310
console.log(`Alice's balance is: ${newAliceBalance}`);
315311

316-
const newBobAccountBalance = await aptos.getAccountResource({
312+
const newBobBalance = await aptos.getAccountAPTAmount({
317313
accountAddress: bob.accountAddress,
318-
resourceType: COIN_STORE,
319314
});
320-
const newBobBalance = Number(newBobAccountBalance.coin.value);
321315
console.log(`Bob's balance is: ${newBobBalance}`);
322316

323317
// Bob should have the transfer amount

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
155155
function: "0x1::aptos_account::transfer",
156156
functionArguments: [bob.accountAddress, 100],
157157
},
158+
// 降低默认 gas 上限以适配常见 devnet 水龙头额度(1 APT)
159+
options: { maxGasAmount: 100_000 },
158160
});
159161
...
160162
```
@@ -225,8 +227,6 @@ import { Aside, Steps, TabItem, Tabs } from '@astrojs/starlight/components';
225227

226228
import { Account, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
227229

228-
const APTOS_COIN = "0x1::aptos_coin::AptosCoin";
229-
const COIN_STORE = `0x1::coin::CoinStore<${APTOS_COIN}>`;
230230
const ALICE_INITIAL_BALANCE = 100_000_000;
231231
const BOB_INITIAL_BALANCE = 100;
232232
const TRANSFER_AMOUNT = 100;
@@ -263,20 +263,16 @@ async function example() {
263263
});
264264
console.log("Alice 和 Bob 的账户已成功注资!");
265265

266-
// 查询新注资账户的余额
266+
// 查询新注资账户的余额(使用同质化资产余额接口;新账户可能没有旧版 CoinStore 资源)
267267
console.log("\n=== 余额 ===\n");
268-
const aliceAccountBalance = await aptos.getAccountResource({
268+
const aliceBalance = await aptos.getAccountAPTAmount({
269269
accountAddress: alice.accountAddress,
270-
resourceType: COIN_STORE,
271270
});
272-
const aliceBalance = Number(aliceAccountBalance.coin.value);
273271
console.log(`Alice 的余额是: ${aliceBalance}`);
274272

275-
const bobAccountBalance = await aptos.getAccountResource({
273+
const bobBalance = await aptos.getAccountAPTAmount({
276274
accountAddress: bob.accountAddress,
277-
resourceType: COIN_STORE,
278275
});
279-
const bobBalance = Number(bobAccountBalance.coin.value);
280276
console.log(`Bob 的余额是: ${bobBalance}`);
281277

282278
// 从 Alice 账户向 Bob 账户发送交易
@@ -285,8 +281,9 @@ async function example() {
285281
data: {
286282
// Aptos 上的所有交易都是通过智能合约实现的。
287283
function: "0x1::aptos_account::transfer",
288-
functionArguments: [bob.accountAddress, 100],
284+
functionArguments: [bob.accountAddress, TRANSFER_AMOUNT],
289285
},
286+
options: { maxGasAmount: 100_000 },
290287
});
291288

292289
console.log("\n=== 转账交易 ===\n");
@@ -299,19 +296,16 @@ async function example() {
299296
const executedTransaction = await aptos.waitForTransaction({
300297
transactionHash: committedTxn.hash,
301298
});
302-
console.log("交易哈希:", executedTransaction.hash); console.log("\n=== 转账后余额 ===\n");
303-
const newAliceAccountBalance = await aptos.getAccountResource({
299+
console.log("交易哈希:", executedTransaction.hash);
300+
console.log("\n=== 转账后余额 ===\n");
301+
const newAliceBalance = await aptos.getAccountAPTAmount({
304302
accountAddress: alice.accountAddress,
305-
resourceType: COIN_STORE,
306303
});
307-
const newAliceBalance = Number(newAliceAccountBalance.coin.value);
308304
console.log(`Alice 的余额是: ${newAliceBalance}`);
309305

310-
const newBobAccountBalance = await aptos.getAccountResource({
306+
const newBobBalance = await aptos.getAccountAPTAmount({
311307
accountAddress: bob.accountAddress,
312-
resourceType: COIN_STORE,
313308
});
314-
const newBobBalance = Number(newBobAccountBalance.coin.value);
315309
console.log(`Bob 的余额是: ${newBobBalance}`);
316310

317311
// Bob 应该收到转账金额

0 commit comments

Comments
 (0)