Skip to content

Commit 5c2716d

Browse files
committed
fix(sdk-core): fix getAccountResources to use POST and correct endpoint path
The SDK was sending GET to /accountResources but the server expects POST to /getAccountResources. Also fix param name from assetName to destinationAddress to match the server contract, and add example script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> TICKET: CHALO-206
1 parent 2c533ce commit 5c2716d

4 files changed

Lines changed: 71 additions & 30 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Get account resources for a Tron wallet at BitGo.
3+
*
4+
* This tool will help you see how to use the BitGo API to easily get
5+
* account resources information for a wallet.
6+
*
7+
* Copyright 2026, BitGo, Inc. All Rights Reserved.
8+
*/
9+
import { BitGo } from 'bitgo';
10+
11+
// TODO: change to 'production' for mainnet
12+
const env = 'test';
13+
const bitgo = new BitGo({ env });
14+
15+
// TODO: change to 'trx' for mainnet or 'ttrx:<token>' for testnet token
16+
const coin = 'ttrx';
17+
18+
// TODO: set your wallet id
19+
const walletId = '';
20+
21+
// TODO: set your access token here
22+
// You can get this from User Settings > Developer Options > Add Access Token
23+
const accessToken = '';
24+
25+
// TODO: set the addresses to query
26+
// Note: To get energy deficit for a token transfer, make sure the token exists in the address.
27+
const addresses = [''];
28+
29+
async function main() {
30+
bitgo.authenticateWithAccessToken({ accessToken });
31+
32+
const wallet = await bitgo.coin(coin).wallets().getWallet({ id: walletId });
33+
34+
console.log('Wallet ID:', wallet.id());
35+
36+
const resources = await wallet.getAccountResources({ addresses });
37+
console.log('Account Resources:', JSON.stringify(resources, null, 2));
38+
}
39+
40+
main().catch((e) => console.error(e));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ export interface ForwarderBalanceOptions {
541541

542542
export interface GetAccountResourcesOptions {
543543
addresses: string[];
544-
assetName?: string;
544+
destinationAddress?: string;
545545
}
546546

547547
export type CreateAddressFormat = 'base58' | 'cashaddr';

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,11 +1468,11 @@ export class Wallet implements IWallet {
14681468

14691469
/**
14701470
* Get account resources for the given addresses
1471-
* @param params - options object containing addresses and optional assetName
1471+
* @param params - options object containing addresses and optional destinationAddress
14721472
* @returns {Promise<any>} - response from WP API
14731473
*/
14741474
async getAccountResources(params: GetAccountResourcesOptions): Promise<any> {
1475-
const { addresses, assetName } = params;
1475+
const { addresses, destinationAddress } = params;
14761476

14771477
if (!Array.isArray(addresses)) {
14781478
throw new Error('addresses must be an array');
@@ -1482,12 +1482,12 @@ export class Wallet implements IWallet {
14821482
throw new Error('addresses array cannot be empty');
14831483
}
14841484

1485-
const query: any = { addresses };
1486-
if (assetName) {
1487-
query.assetName = assetName;
1485+
const body: any = { addresses };
1486+
if (destinationAddress) {
1487+
body.destinationAddress = destinationAddress;
14881488
}
14891489

1490-
return this.bitgo.get(this.url('/accountResources')).query(query).result();
1490+
return this.bitgo.post(this.url('/getAccountResources')).send(body).result();
14911491
}
14921492

14931493
async updateWalletBuildDefaults(params: UpdateBuildDefaultOptions): Promise<unknown> {

modules/sdk-core/test/unit/bitgo/wallet/getAccountResources.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as assert from 'assert';
22
import * as sinon from 'sinon';
33
import 'should';
4-
import { Wallet } from '../../../../src/bitgo/wallet/wallet';
4+
import { Wallet } from '../../../../src';
55

66
describe('Wallet - getAccountResources', function () {
77
let wallet: Wallet;
@@ -11,11 +11,12 @@ describe('Wallet - getAccountResources', function () {
1111

1212
beforeEach(function () {
1313
mockBitGo = {
14-
get: sinon.stub(),
14+
post: sinon.stub(),
1515
};
1616

1717
mockBaseCoin = {
1818
url: sinon.stub().returns('/test/coin'),
19+
supportsTss: sinon.stub().returns(false),
1920
};
2021

2122
mockWalletData = {
@@ -39,8 +40,8 @@ describe('Wallet - getAccountResources', function () {
3940
],
4041
};
4142

42-
mockBitGo.get.returns({
43-
query: sinon.stub().returns({
43+
mockBitGo.post.returns({
44+
send: sinon.stub().returns({
4445
result: sinon.stub().resolves(mockResponse),
4546
}),
4647
});
@@ -49,30 +50,30 @@ describe('Wallet - getAccountResources', function () {
4950
const result = await wallet.getAccountResources({ addresses });
5051

5152
result.should.deepEqual(mockResponse);
52-
mockBitGo.get.should.have.been.calledOnce;
53-
const queryStub = mockBitGo.get.returnValues[0].query;
54-
queryStub.should.have.been.calledWith({ addresses });
53+
sinon.assert.calledOnce(mockBitGo.post);
54+
const sendStub = mockBitGo.post.returnValues[0].send;
55+
sinon.assert.calledWith(sendStub, { addresses });
5556
});
5657

57-
it('should call WP API with addresses and assetName parameters', async function () {
58+
it('should call WP API with addresses and destinationAddress parameters', async function () {
5859
const mockResponse = {
59-
resources: [{ address: 'address1', balance: 100, token: 'USDT' }],
60+
resources: [{ address: 'address1', balance: 100 }],
6061
};
6162

62-
mockBitGo.get.returns({
63-
query: sinon.stub().returns({
63+
mockBitGo.post.returns({
64+
send: sinon.stub().returns({
6465
result: sinon.stub().resolves(mockResponse),
6566
}),
6667
});
6768

6869
const addresses = ['address1'];
69-
const assetName = 'USDT';
70-
const result = await wallet.getAccountResources({ addresses, assetName });
70+
const destinationAddress = 'TDestAddress123';
71+
const result = await wallet.getAccountResources({ addresses, destinationAddress });
7172

7273
result.should.deepEqual(mockResponse);
73-
mockBitGo.get.should.have.been.calledOnce;
74-
const queryStub = mockBitGo.get.returnValues[0].query;
75-
queryStub.should.have.been.calledWith({ addresses, assetName });
74+
sinon.assert.calledOnce(mockBitGo.post);
75+
const sendStub = mockBitGo.post.returnValues[0].send;
76+
sinon.assert.calledWith(sendStub, { addresses, destinationAddress });
7677
});
7778

7879
it('should throw error if addresses is not an array', async function () {
@@ -93,22 +94,22 @@ describe('Wallet - getAccountResources', function () {
9394
}
9495
});
9596

96-
it('should not include assetName in query if not provided', async function () {
97+
it('should not include destinationAddress in body if not provided', async function () {
9798
const mockResponse = { resources: [] };
9899

99-
mockBitGo.get.returns({
100-
query: sinon.stub().returns({
100+
mockBitGo.post.returns({
101+
send: sinon.stub().returns({
101102
result: sinon.stub().resolves(mockResponse),
102103
}),
103104
});
104105

105106
const addresses = ['address1'];
106107
await wallet.getAccountResources({ addresses });
107108

108-
const queryStub = mockBitGo.get.returnValues[0].query;
109-
const queryArg = queryStub.firstCall.args[0];
110-
queryArg.should.deepEqual({ addresses });
111-
queryArg.should.not.have.property('assetName');
109+
const sendStub = mockBitGo.post.returnValues[0].send;
110+
const sendArg = sendStub.firstCall.args[0];
111+
sendArg.should.deepEqual({ addresses });
112+
sendArg.should.not.have.property('destinationAddress');
112113
});
113114
});
114115
});

0 commit comments

Comments
 (0)