|
| 1 | +/** |
| 2 | + * Create a Go Account wallet at BitGo. |
| 3 | + * This makes use of the convenience function generateWallet with type: 'trading' |
| 4 | + * |
| 5 | + * IMPORTANT: You must backup the encrypted private key and encrypted wallet passphrase! |
| 6 | + * |
| 7 | + * Copyright 2025, BitGo, Inc. All Rights Reserved. |
| 8 | + */ |
| 9 | + |
| 10 | +import { BitGoAPI } from '@bitgo/sdk-api'; |
| 11 | +import { coins } from 'bitgo'; |
| 12 | +require('dotenv').config({ path: '../../.env' }); |
| 13 | + |
| 14 | +const bitgo = new BitGoAPI({ |
| 15 | + accessToken: process.env.TESTNET_ACCESS_TOKEN, |
| 16 | + env: 'test', // Change this to env: 'production' when you are ready for production |
| 17 | +}); |
| 18 | + |
| 19 | +// Go Accounts use the 'ofc' (Off-Chain) coin |
| 20 | +const coin = 'ofc'; |
| 21 | +bitgo.register(coin, coins.Ofc.createInstance); |
| 22 | + |
| 23 | +// TODO: set a label for your new Go Account here |
| 24 | +const label = 'Example Go Account Wallet'; |
| 25 | + |
| 26 | +// TODO: set your passphrase for your new wallet here (encrypts the private key) |
| 27 | +const passphrase = 'go_account_wallet_passphrase'; |
| 28 | + |
| 29 | +// TODO: set your passcode encryption code here (encrypts the passphrase itself) |
| 30 | +const passcodeEncryptionCode = 'encryption_code_for_passphrase'; |
| 31 | + |
| 32 | +// TODO: set your enterprise ID for your new wallet here |
| 33 | +const enterprise = 'your_enterprise_id'; |
| 34 | + |
| 35 | +async function main() { |
| 36 | + const response = await bitgo.coin(coin).wallets().generateWallet({ |
| 37 | + label, |
| 38 | + passphrase, |
| 39 | + passcodeEncryptionCode, |
| 40 | + enterprise, |
| 41 | + type: 'trading', // Required for Go Accounts |
| 42 | + }); |
| 43 | + |
| 44 | + // Type guard to ensure we got a Go Account response |
| 45 | + if (!('userKeychain' in response)) { |
| 46 | + throw new Error('Go account missing required user keychain'); |
| 47 | + } |
| 48 | + |
| 49 | + const { wallet, userKeychain, encryptedWalletPassphrase } = response; |
| 50 | + |
| 51 | + console.log(`Wallet ID: ${wallet.id()}`); |
| 52 | + |
| 53 | + console.log('BACKUP THE FOLLOWING INFORMATION: '); |
| 54 | + console.log('User Keychain:'); |
| 55 | + console.log(`Keychain ID: ${userKeychain.id}`); |
| 56 | + console.log(`Public Key: ${userKeychain.pub}`); |
| 57 | + console.log(`Encrypted Private Key: ${userKeychain.encryptedPrv}`); |
| 58 | + |
| 59 | + console.log(`Encrypted Wallet Passphrase: ${encryptedWalletPassphrase}`); |
| 60 | + |
| 61 | + // Create receive address for Go Account |
| 62 | + const receiveAddress = await wallet.createAddress(); |
| 63 | + console.log('Go Account Receive Address:', receiveAddress.address); |
| 64 | +} |
| 65 | + |
| 66 | +main().catch((e) => console.error('Error creating Go Account:', e)); |
| 67 | + |
0 commit comments