From 082489fec0c49d18c64a486a76ff65400fd5c70b Mon Sep 17 00:00:00 2001 From: fgfm999 Date: Mon, 12 Dec 2022 20:29:49 +0800 Subject: [PATCH] [TS SDK] use getAccountResource in checkBalance --- ecosystem/typescript/sdk/CHANGELOG.md | 1 + ecosystem/typescript/sdk/src/coin_client.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ecosystem/typescript/sdk/CHANGELOG.md b/ecosystem/typescript/sdk/CHANGELOG.md index 336787def2791..6e4d3127c97ed 100644 --- a/ecosystem/typescript/sdk/CHANGELOG.md +++ b/ecosystem/typescript/sdk/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the Aptos Node SDK will be captured in this file. This ch - Export classes from property_map_serde - User can specify token string property type using "string", "String" or "0x1::string::String" to serde the string token property on-chain +- Use `getAccountResource` to replace `getAccountResources` in `CoinClient#checkBalance`, which can reduce network load. ## 1.4.0 (2022-11-30) diff --git a/ecosystem/typescript/sdk/src/coin_client.ts b/ecosystem/typescript/sdk/src/coin_client.ts index 272267bd90474..d6ba4d2aa78ff 100644 --- a/ecosystem/typescript/sdk/src/coin_client.ts +++ b/ecosystem/typescript/sdk/src/coin_client.ts @@ -97,8 +97,7 @@ export class CoinClient { const coinType = extraArgs?.coinType ?? APTOS_COIN; const typeTag = `0x1::coin::CoinStore<${coinType}>`; const address = getAddressFromAccountOrAddress(account); - const resources = await this.aptosClient.getAccountResources(address); - const accountResource = resources.find((r) => r.type === typeTag); - return BigInt((accountResource!.data as any).coin.value); + const accountResource = await this.aptosClient.getAccountResource(address, typeTag); + return BigInt((accountResource.data as any).coin.value); } // <:!:checkBalance }