Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/ts/list-wallet-addresses-by-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
const addresses = await wallet.addressesByBalance({
token: 'tapt:usdt',
});
console.log(JSON.stringify(addresses.addresses));
console.log(JSON.stringify(addresses.addresses, null, 2));
}

main().catch((e) => console.error(e));
85 changes: 85 additions & 0 deletions examples/ts/trx/delegate-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Build and sign a TRX DelegateResource transaction via the BitGo platform.
*
* DelegateResource allows a TRX holder who has frozen TRX (via FreezeBalanceV2)
* to delegate the resulting BANDWIDTH or ENERGY resources to another address,
* without transferring TRX itself.
*
* Prerequisites:
* - Valid BitGo access token
* - TRX wallet with frozen balance (via FreezeBalanceV2)
* - Wallet passphrase for signing
*
* Copyright 2026, BitGo, Inc. All Rights Reserved.
*/
import { WalletCoinSpecific } from 'bitgo';
import { BitGoAPI } from '@bitgo/sdk-api';
import { Ttrx } from '@bitgo/sdk-coin-trx';
require('dotenv').config({ path: '../../../.env' });

// TODO: change to 'production' for mainnet
const bitgo = new BitGoAPI({
accessToken: process.env.TESTNET_ACCESS_TOKEN,
env: 'test',
});

const coin = 'ttrx';
bitgo.register(coin, Ttrx.createInstance);

// TODO: set your wallet id
const walletId = '';

// TODO: set your wallet passphrase
const walletPassphrase = '';

// TODO: set OTP code
const otp = '000000';

// TODO: set the receiver address (the address that will use the delegated resources)
const receiverAddress = '';

// TODO: set the amount of frozen TRX to delegate, in SUN (1 TRX = 1,000,000 SUN)
const amountSun = '1000000';

// TODO: set the resource type to delegate: 'ENERGY' or 'BANDWIDTH'
const resource = 'BANDWIDTH';

async function main() {
const wallet = await bitgo.coin(coin).wallets().getWallet({ id: walletId });
const coinSpecific = wallet.coinSpecific() as WalletCoinSpecific;
const ownerAddress = coinSpecific.rootAddress;

console.log('Wallet ID:', wallet.id());
console.log('Owner Address:', ownerAddress);

// Unlock the session for signing
const unlock = await bitgo.unlock({ otp, duration: 3600 });
if (!unlock) {
throw new Error('error unlocking session');
}

// Build, sign, and send the transaction in one step
// The SDK handles prebuild, user half-sign, platform co-signing, and broadcasting
const result = await wallet.sendMany({
type: 'delegateResource',
stakingParams: {
owner_address: ownerAddress,
receiver_address: receiverAddress,
amount: amountSun,
resource,
},
recipients: [
{
address: receiverAddress,
amount: '0',
},
],
walletPassphrase,
});

console.log('Transaction sent successfully!');
console.log('TX ID:', result.txid);
console.log('Result:', JSON.stringify(result, null, 2));
}

main().catch((e) => console.error(e));
16 changes: 8 additions & 8 deletions examples/ts/trx/get-account-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@
*
* Copyright 2026, BitGo, Inc. All Rights Reserved.
*/
import { BitGo } from 'bitgo';
import { BitGoAPI } from "@bitgo/sdk-api";
import { Ttrx } from "@bitgo/sdk-coin-trx";
require('dotenv').config({ path: '../../../.env' });

// TODO: change to 'production' for mainnet
const env = 'test';
const bitgo = new BitGo({ env });
const bitgo = new BitGoAPI({
accessToken: process.env.TESTNET_ACCESS_TOKEN,
env: 'test',
});

// TODO: change to 'trx' for mainnet or 'ttrx:<token>' for testnet token
const coin = 'ttrx';
bitgo.register(coin, Ttrx.createInstance);

// TODO: set your wallet id
const walletId = '';

// TODO: set your access token here
// You can get this from User Settings > Developer Options > Add Access Token
const accessToken = '';

// TODO: set the addresses to query
// Note: To get energy deficit for a token transfer, make sure the token exists in the address.
const addresses = [''];

async function main() {
bitgo.authenticateWithAccessToken({ accessToken });

const wallet = await bitgo.coin(coin).wallets().getWallet({ id: walletId });

Expand Down
57 changes: 57 additions & 0 deletions examples/ts/trx/get-resource-delegations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Get resource delegations for a TRX wallet at BitGo.
*
* This tool will help you see how to use the BitGo API to query
* outgoing and incoming ENERGY/BANDWIDTH delegations for a wallet.
*
* Prerequisites:
* - Valid BitGo access token
* - TRX wallet ID
*
* Copyright 2026, BitGo, Inc. All Rights Reserved.
*/
import { BitGoAPI } from '@bitgo/sdk-api';
import { Ttrx } from '@bitgo/sdk-coin-trx';
require('dotenv').config({ path: '../../../.env' });

// TODO: change to 'production' for mainnet
const bitgo = new BitGoAPI({
accessToken: process.env.TESTNET_ACCESS_TOKEN,
env: 'test',
});

// TODO: change to 'trx' for mainnet
const coin = 'ttrx';
bitgo.register(coin, Ttrx.createInstance);

// TODO: set your wallet id
const walletId = '';

// TODO: (optional) filter by delegation type
const type: 'outgoing' | 'incoming' | undefined = undefined;

// TODO: (optional) filter by resource type: 'ENERGY' or 'BANDWIDTH'
const resourceType: 'ENERGY' | 'BANDWIDTH' | undefined = undefined;

// TODO: (optional) maximum number of results to return
const limit: number | undefined = undefined;

async function main() {
const queryParams: Record<string, string | number> = {};
if (type !== undefined) queryParams.type = type;
if (resourceType !== undefined) queryParams.resourceType = resourceType;
if (limit !== undefined) queryParams.limit = limit;

const result = await bitgo
.get(bitgo.url(`/${coin}/wallet/${walletId}/resourcedelegations`, 2))
.query(queryParams)
.result();

console.log('Wallet Address:', result.address);
console.log('Coin:', result.coin);
console.log('Outgoing Delegations:', result.delegations.outgoing.length);
console.log('Incoming Delegations:', result.delegations.incoming.length);
console.log('Resource Delegations:', JSON.stringify(result, null, 2));
}

main().catch((e) => console.error(e));
86 changes: 86 additions & 0 deletions examples/ts/trx/undelegate-resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Build and sign a TRX UndelegateResource transaction via the BitGo platform.
*
* DelegateResource allows a TRX holder who has frozen TRX (via FreezeBalanceV2)
* to delegate the resulting BANDWIDTH or ENERGY resources to another address,
* without transferring TRX itself.
*
* Prerequisites:
* - Valid BitGo access token
* - TRX wallet with frozen balance (via FreezeBalanceV2)
* - Wallet passphrase for signing
*
* Copyright 2026, BitGo, Inc. All Rights Reserved.
*/
import { WalletCoinSpecific } from 'bitgo';
import {BitGoAPI} from "@bitgo/sdk-api";
import {Ttrx} from "@bitgo/sdk-coin-trx";
require('dotenv').config({ path: '../../../.env' });

// TODO: change to 'production' for mainnet
const bitgo = new BitGoAPI({
accessToken: process.env.TESTNET_ACCESS_TOKEN,
env: 'test',
});

const coin = 'ttrx';
bitgo.register(coin, Ttrx.createInstance);

// TODO: set your wallet id
const walletId = '';

// TODO: set your wallet passphrase
const walletPassphrase = '';

// TODO: set OTP code
const otp = '000000';

// TODO: set the receiver address (the address that will use the delegated resources)
const receiverAddress = '';

// TODO: set the amount of frozen TRX to delegate, in SUN (1 TRX = 1,000,000 SUN)
const amountSun = '1000000';

// TODO: set the resource type to delegate: 'ENERGY' or 'BANDWIDTH'
const resource = 'BANDWIDTH';

async function main() {

const wallet = await bitgo.coin(coin).wallets().getWallet({ id: walletId });
const coinSpecific = wallet.coinSpecific() as WalletCoinSpecific;
const ownerAddress = coinSpecific.rootAddress;

console.log('Wallet ID:', wallet.id());
console.log('Owner Address:', ownerAddress);

// Unlock the session for signing
const unlock = await bitgo.unlock({ otp, duration: 3600 });
if (!unlock) {
throw new Error('error unlocking session');
}

// Build, sign, and send the transaction in one step
// The SDK handles prebuild, user half-sign, platform co-signing, and broadcasting
const result = await wallet.sendMany({
type: 'undelegateResource',
stakingParams: {
owner_address: ownerAddress,
receiver_address: receiverAddress,
amount: amountSun,
resource,
},
recipients: [
{
address: receiverAddress,
amount: '0',
},
],
walletPassphrase,
});

console.log('Transaction sent successfully!');
console.log('TX ID:', result.txid);
console.log('Result:', JSON.stringify(result, null, 2));
}

main().catch((e) => console.error(e));
Loading