Skip to content

Commit d7d12b7

Browse files
authored
Merge pull request #8328 from BitGo/CAAS-1013-add-go-account-approval-script
chore: update go account examples documentation
2 parents 95bcb69 + 8626aab commit d7d12b7

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

examples/docs/go-account-creation.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,72 @@ This guide demonstrates how to create Go Accounts (trading wallets) using only t
1212

1313
## Available Scripts
1414

15+
### 4. Go Account Withdrawal — complete flow
16+
**File:** `examples/ts/go-account/go-account-withdrawal.ts`
17+
18+
Runs all three withdrawal steps in a single script: build → sign → submit.
19+
20+
**Best for:**
21+
- End-to-end withdrawal from a Go Account (OFC) wallet in one command
22+
- Quick integration and testing
23+
24+
**Flow:**
25+
```
26+
Step 1: wallet.prebuildTransaction({ recipients: [...] }) → prebuild
27+
Step 2: tradingAccount.signPayload({ payload: prebuild.payload, walletPassphrase }) → signature
28+
Step 3: POST /tx/send { halfSigned: { payload, signature } } → txid/pendingApproval
29+
```
30+
31+
> **Note:** If your enterprise has an approval policy configured, Step 3 returns a
32+
> pending approval instead of a txid. Run `go-account-approve.ts` from a second
33+
> admin account to approve it.
34+
35+
### 5. Go Account Approval — approve a pending withdrawal
36+
**File:** `examples/ts/go-account/go-account-approve.ts`
37+
38+
Approves a pending withdrawal that was held for review by an approval policy.
39+
40+
**Best for:**
41+
- Enterprises that require a second admin to approve withdrawals
42+
- Auditing or reviewing pending transactions before they are broadcast
43+
44+
**Important:** You cannot approve your own transaction — a **different** admin must run this script.
45+
46+
**Flow:**
47+
```
48+
Step 1: coin.pendingApprovals().list({ walletId }) → find pending approval
49+
Step 2: pendingApproval.approve({ walletPassphrase }) → PUT /pendingapprovals/{id}
50+
```
51+
52+
**Example:**
53+
```typescript
54+
const { pendingApprovals } = await coin.pendingApprovals().list({ walletId });
55+
const approval = pendingApprovals.find((pa) => pa.state() === 'pending');
56+
await approval.approve({ walletPassphrase, otp });
57+
```
58+
59+
### 6. Sign Transaction — sign only (Step 2 of 3)
60+
**File:** `examples/ts/go-account/sign-transaction.ts`
61+
62+
Signs a pre-built payload and outputs the hex signature. Use this when the build
63+
step (Step 1) happens in a separate process and you only need to sign offline.
64+
65+
**Best for:**
66+
- Architectures where build and sign happen in different services/environments
67+
- Auditing or debugging the signing step in isolation
68+
69+
**Example:**
70+
```typescript
71+
const tradingAccount = wallet.toTradingAccount();
72+
const signature = await tradingAccount.signPayload({
73+
payload: prebuildPayload, // stringified JSON from Step 1
74+
walletPassphrase: 'your_wallet_passphrase',
75+
});
76+
// → pass signature + payload to Step 3 (submitTransaction)
77+
```
78+
79+
---
80+
1581
### 1. SDK Approach (Recommended)
1682
**File:** `examples/ts/go-account/create-go-account.ts`
1783

@@ -213,6 +279,18 @@ const usdtAddress = await wallet.createAddress({
213279

214280
# Create an address for an existing wallet
215281
npx tsx create-go-account-address.ts
282+
283+
# Full withdrawal: build + sign + submit in one command
284+
OFC_WALLET_ID=your_wallet_id OFC_WALLET_PASSPHRASE=your_passphrase npx tsx go-account-withdrawal.ts
285+
286+
# Approve a pending withdrawal (run as a DIFFERENT admin)
287+
TESTNET_ACCESS_TOKEN=approver_token OFC_WALLET_ID=your_wallet_id OFC_WALLET_PASSPHRASE=approver_passphrase npx tsx go-account-approve.ts
288+
289+
# Approve a specific pending approval by ID
290+
TESTNET_ACCESS_TOKEN=approver_token PENDING_APPROVAL_ID=your_approval_id OFC_WALLET_PASSPHRASE=approver_passphrase npx tsx go-account-approve.ts
291+
292+
# Sign only: sign a pre-built payload (Step 2 of 3)
293+
OFC_WALLET_ID=your_wallet_id OFC_WALLET_PASSPHRASE=your_passphrase OFC_PREBUILD_PAYLOAD='{"..."}' npx tsx sign-transaction.ts
216294
```
217295

218296
## Supported Tokens

0 commit comments

Comments
 (0)