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

[TS SDK] use getAccountResource in checkBalance #5860

Merged
merged 1 commit into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions ecosystem/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions ecosystem/typescript/sdk/src/coin_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}