Skip to content

Commit 71163f2

Browse files
authored
Merge pull request #6043 from BitGo/coin-3909-list-addresses-v2-script
feat: list wallet addresses sorted by balance
2 parents bd019f5 + 6835c5d commit 71163f2

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* List addresses by sorted balances on a wallet.
3+
*
4+
* Copyright 2025, BitGo, Inc. All Rights Reserved.
5+
*/
6+
import { BitGoAPI } from '@bitgo/sdk-api';
7+
import {Tapt} from "@bitgo/sdk-coin-apt";
8+
require('dotenv').config({ path: '../../.env' });
9+
10+
const bitgo = new BitGoAPI({
11+
accessToken: process.env.TESTNET_ACCESS_TOKEN,
12+
env: 'test',
13+
});
14+
15+
const coin = 'tapt';
16+
bitgo.register(coin, Tapt.createInstance);
17+
18+
const walletId = '';
19+
20+
async function main() {
21+
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
22+
const addresses = await wallet.addressesByBalance({
23+
token: 'tapt:usdt',
24+
});
25+
console.log(JSON.stringify(addresses.addresses));
26+
}
27+
28+
main().catch((e) => console.error(e));

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export interface WalletCoinSpecific {
284284
}
285285

286286
export interface PaginationOptions {
287+
page?: number;
287288
prevId?: string;
288289
limit?: number;
289290
}
@@ -418,6 +419,11 @@ export interface AddressesOptions extends PaginationOptions {
418419
pendingDeployment?: boolean;
419420
}
420421

422+
export interface AddressesByBalanceOptions extends PaginationOptions {
423+
token: string;
424+
sort?: number;
425+
}
426+
421427
export interface GetAddressOptions {
422428
address?: string;
423429
id?: string;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
} from '../utils';
3838
import {
3939
AccelerateTransactionOptions,
40+
AddressesByBalanceOptions,
4041
AddressesOptions,
4142
BuildConsolidationTransactionOptions,
4243
BuildTokenEnablementOptions,
@@ -1132,6 +1133,38 @@ export class Wallet implements IWallet {
11321133
.result();
11331134
}
11341135

1136+
/**
1137+
* List the addresses sorted by balance for a given wallet
1138+
* @param params
1139+
* @returns {*}
1140+
*/
1141+
async addressesByBalance(params: AddressesByBalanceOptions): Promise<any> {
1142+
const query: AddressesByBalanceOptions = {
1143+
token: params.token,
1144+
};
1145+
query.sort = params.sort ?? -1;
1146+
query.page = params.page ?? 1;
1147+
query.limit = params.limit ?? 500;
1148+
1149+
if (!_.isNumber(query.sort)) {
1150+
throw new Error('invalid sort argument, expecting number');
1151+
}
1152+
if (!_.isNumber(query.page)) {
1153+
throw new Error('invalid page argument, expecting number');
1154+
}
1155+
if (!_.isNumber(params.limit)) {
1156+
throw new Error('invalid limit argument, expecting number');
1157+
}
1158+
if (params.limit < 1 || params.limit > 500) {
1159+
throw new Error('limit argument must be between 1 and 500');
1160+
}
1161+
1162+
return this.bitgo
1163+
.get(this.baseCoin.url('/wallet/' + this._wallet.id + '/addresses/balances'))
1164+
.query(query)
1165+
.result();
1166+
}
1167+
11351168
/**
11361169
* Get a single wallet address by its id
11371170
* @param params

0 commit comments

Comments
 (0)