Skip to content
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
38 changes: 33 additions & 5 deletions examples/docs/go-account-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ This guide demonstrates how to create Go Accounts (trading wallets) using only t
- Full control over the wallet creation process
- Production-ready code with proper error handling

## Two Approaches
## Available Scripts

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

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

Expand Down Expand Up @@ -44,7 +44,7 @@ const { wallet, userKeychain, encryptedWalletPassphrase } = response;
```

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

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

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

### 3. Creating Addresses for Existing Wallets
**File:** `examples/ts/go-account/create-go-account-address.ts`

Demonstrates how to create additional addresses for an existing Go Account wallet.

**Best for:**
- Adding new addresses to existing wallets
- Creating addresses for different tokens
- Managing multiple receiving addresses

**Example:**
```typescript
const wallet = await bitgo.coin('ofc').wallets().get({ id: walletId });

const address = await wallet.createAddress({
label: 'My New Address',
onToken: 'ofctsol:usdc' // Required for OFC wallets
});
```

## Detailed Examples

### SDK Approach Example
```typescript
// Step 1: Create keychain locally
const keychain = bitgo.coin('ofc').keychains().create();

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

4. Run the script:
```bash
cd examples/ts
cd examples/ts/go-account

# Create a new Go Account wallet (recommended)
npx tsx create-go-account.ts
# or for advanced approach:

# Create a new Go Account wallet (advanced approach)
npx tsx create-go-account-advanced.ts

# Create an address for an existing wallet
npx tsx create-go-account-address.ts
```

## Supported Tokens
Expand Down
76 changes: 76 additions & 0 deletions examples/ts/go-account/create-go-account-address.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Create an Address for an Existing Go Account Wallet
*
* This example demonstrates how to create a new address for an existing Go Account
* wallet. This is useful when you need to generate additional receiving addresses
* for different tokens or purposes.
*
* This does NOT use BitGo Express - it communicates directly with BitGo platform APIs.
*
* IMPORTANT: For Go Account (OFC) wallets, the onToken parameter is always required
* when creating addresses.
*
* Copyright 2025, BitGo, Inc. All Rights Reserved.
*/

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

// Initialize BitGo SDK
const bitgo = new BitGoAPI({
accessToken: process.env.TESTNET_ACCESS_TOKEN,
env: 'test', // Change this to env: 'production' when you are ready for production
});

// Go Accounts use the 'ofc' (Off-Chain) coin
const coin = 'ofc';
bitgo.register(coin, coins.Ofc.createInstance);

// Configuration - Update these values
const walletId = 'your_wallet_id'; // The ID of your existing Go Account wallet
const addressLabel = 'My New Address 2'; // Label for the new address

// Token to create address for (required for OFC wallets)
// Examples: 'ofctsol:usdc', 'ofctsol:usdt', 'ofcttrx:usdt', 'ofctbtc'
const token = 'ofcttrx:usdt';

async function main() {
console.log('=== Creating Address for Go Account ===\n');

// Step 1: Get the existing wallet
console.log(`Retrieving wallet: ${walletId}...`);
const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
console.log(`✓ Wallet retrieved: ${wallet.label()}`);
console.log(` Wallet Type: ${wallet.type()}`);
console.log(` Wallet Coin: ${wallet.coin()}`);

// Step 2: Create a new address for the specified token
console.log(`\nCreating address for token ${token}...`);
try {
const address = await wallet.createAddress({
label: addressLabel,
onToken: token // Required for OFC wallets
});

console.log(`✓ Address created: ${address.address}`);
console.log('\nAddress Response:');
console.log(JSON.stringify(address, null, 2));

console.log('\n✓ Address creation complete!');
console.log('\nNext Steps:');
console.log('1. Use this address to receive ' + token + ' tokens');
console.log('2. Share this address with senders');
console.log('3. Create additional addresses: wallet.createAddress({ label: "...", onToken: "..." })');

} catch (error) {
console.log(` Error: Address creation failed. Token may not be enabled.`);
console.error(` Error: ${error}`);
throw error;
}
}

main().catch((e) => {
console.error('\n❌ Error creating address:', e);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { BitGoAPI } from '@bitgo/sdk-api';
import { Wallet } from '@bitgo/sdk-core';
import { coins } from 'bitgo';
require('dotenv').config({ path: '../../.env' });
require('dotenv').config({ path: '../../../.env' });

// Initialize BitGo SDK
const bitgo = new BitGoAPI({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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

// Initialize BitGo SDK
const bitgo = new BitGoAPI({
Expand Down