Skip to content

Commit cab06bc

Browse files
committed
feat: add go account address creation script
CAAS-739 TICKET: CAAS-739
1 parent bd893c9 commit cab06bc

4 files changed

Lines changed: 111 additions & 7 deletions

File tree

examples/docs/go-account-creation.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ This guide demonstrates how to create Go Accounts (trading wallets) using only t
1010
- Full control over the wallet creation process
1111
- Production-ready code with proper error handling
1212

13-
## Two Approaches
13+
## Available Scripts
1414

1515
### 1. SDK Approach (Recommended)
16-
**File:** `examples/ts/create-go-account.ts`
16+
**File:** `examples/ts/go-account/create-go-account.ts`
1717

1818
Uses the high-level `generateWallet()` method which handles keychain creation, encryption, and wallet setup automatically.
1919

@@ -44,7 +44,7 @@ const { wallet, userKeychain, encryptedWalletPassphrase } = response;
4444
```
4545

4646
### 2. Advanced SDK Approach
47-
**File:** `examples/ts/create-go-account-advanced.ts`
47+
**File:** `examples/ts/go-account/create-go-account-advanced.ts`
4848

4949
Provides manual control over keychain creation and wallet setup using SDK methods.
5050

@@ -54,8 +54,30 @@ Provides manual control over keychain creation and wallet setup using SDK method
5454
- Understanding the internals of Go Account creation
5555
- Testing and debugging
5656

57+
### 3. Creating Addresses for Existing Wallets
58+
**File:** `examples/ts/go-account/create-go-account-address.ts`
59+
60+
Demonstrates how to create additional addresses for an existing Go Account wallet.
61+
62+
**Best for:**
63+
- Adding new addresses to existing wallets
64+
- Creating addresses for different tokens
65+
- Managing multiple receiving addresses
66+
5767
**Example:**
5868
```typescript
69+
const wallet = await bitgo.coin('ofc').wallets().get({ id: walletId });
70+
71+
const address = await wallet.createAddress({
72+
label: 'My New Address',
73+
onToken: 'ofctsol:usdc' // Required for OFC wallets
74+
});
75+
```
76+
77+
## Detailed Examples
78+
79+
### SDK Approach Example
80+
```typescript
5981
// Step 1: Create keychain locally
6082
const keychain = bitgo.coin('ofc').keychains().create();
6183

@@ -181,10 +203,16 @@ const usdtAddress = await wallet.createAddress({
181203

182204
4. Run the script:
183205
```bash
184-
cd examples/ts
206+
cd examples/ts/go-account
207+
208+
# Create a new Go Account wallet (recommended)
185209
npx tsx create-go-account.ts
186-
# or for advanced approach:
210+
211+
# Create a new Go Account wallet (advanced approach)
187212
npx tsx create-go-account-advanced.ts
213+
214+
# Create an address for an existing wallet
215+
npx tsx create-go-account-address.ts
188216
```
189217

190218
## Supported Tokens
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Create an Address for an Existing Go Account Wallet
3+
*
4+
* This example demonstrates how to create a new address for an existing Go Account
5+
* wallet. This is useful when you need to generate additional receiving addresses
6+
* for different tokens or purposes.
7+
*
8+
* This does NOT use BitGo Express - it communicates directly with BitGo platform APIs.
9+
*
10+
* IMPORTANT: For Go Account (OFC) wallets, the onToken parameter is always required
11+
* when creating addresses.
12+
*
13+
* Copyright 2025, BitGo, Inc. All Rights Reserved.
14+
*/
15+
16+
import { BitGoAPI } from '@bitgo/sdk-api';
17+
import { coins } from 'bitgo';
18+
require('dotenv').config({ path: '../../../.env' });
19+
20+
// Initialize BitGo SDK
21+
const bitgo = new BitGoAPI({
22+
accessToken: process.env.TESTNET_ACCESS_TOKEN,
23+
env: 'test', // Change this to env: 'production' when you are ready for production
24+
});
25+
26+
// Go Accounts use the 'ofc' (Off-Chain) coin
27+
const coin = 'ofc';
28+
bitgo.register(coin, coins.Ofc.createInstance);
29+
30+
// Configuration - Update these values
31+
const walletId = '69861e14c54dbd6e00c585526f9f4152'; // The ID of your existing Go Account wallet
32+
const addressLabel = 'My New Address 2'; // Label for the new address
33+
34+
// Token to create address for (required for OFC wallets)
35+
// Examples: 'ofctsol:usdc', 'ofctsol:usdt', 'ofcttrx:usdt', 'ofctbtc'
36+
const token = 'ofcttrx:usdt';
37+
38+
async function main() {
39+
console.log('=== Creating Address for Go Account ===\n');
40+
41+
// Step 1: Get the existing wallet
42+
console.log(`Retrieving wallet: ${walletId}...`);
43+
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
44+
console.log(`✓ Wallet retrieved: ${wallet.label()}`);
45+
console.log(` Wallet Type: ${wallet.type()}`);
46+
console.log(` Wallet Coin: ${wallet.coin()}`);
47+
48+
// Step 2: Create a new address for the specified token
49+
console.log(`\nCreating address for token ${token}...`);
50+
try {
51+
const address = await wallet.createAddress({
52+
label: addressLabel,
53+
onToken: token // Required for OFC wallets
54+
});
55+
56+
console.log(`✓ Address created: ${address.address}`);
57+
console.log('\nAddress Response:');
58+
console.log(JSON.stringify(address, null, 2));
59+
60+
console.log('\n✓ Address creation complete!');
61+
console.log('\nNext Steps:');
62+
console.log('1. Use this address to receive ' + token + ' tokens');
63+
console.log('2. Share this address with senders');
64+
console.log('3. Create additional addresses: wallet.createAddress({ label: "...", onToken: "..." })');
65+
66+
} catch (error) {
67+
console.log(` Error: Address creation failed. Token may not be enabled.`);
68+
console.error(` Error: ${error}`);
69+
throw error;
70+
}
71+
}
72+
73+
main().catch((e) => {
74+
console.error('\n❌ Error creating address:', e);
75+
process.exit(1);
76+
});

examples/ts/create-go-account-advanced.ts renamed to examples/ts/go-account/create-go-account-advanced.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import { BitGoAPI } from '@bitgo/sdk-api';
2222
import { Wallet } from '@bitgo/sdk-core';
2323
import { coins } from 'bitgo';
24-
require('dotenv').config({ path: '../../.env' });
24+
require('dotenv').config({ path: '../../../.env' });
2525

2626
// Initialize BitGo SDK
2727
const bitgo = new BitGoAPI({

examples/ts/create-go-account.ts renamed to examples/ts/go-account/create-go-account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { BitGoAPI } from '@bitgo/sdk-api';
1818
import { coins } from 'bitgo';
19-
require('dotenv').config({ path: '../../.env' });
19+
require('dotenv').config({ path: '../../../.env' });
2020

2121
// Initialize BitGo SDK
2222
const bitgo = new BitGoAPI({

0 commit comments

Comments
 (0)