Install SDK

Overview

The BitGo JavaScript SDK and npm libraries enable you to build apps and services for all the Coins and Tokens that BitGo supports. The SDK is an out-of-the-box solution that runs in a browser or Node.js and solves complicated transactional logic required to integrate BitGo REST APIs.

You can use the SDK to:

  • Create and manage wallets and addresses.
  • Create and execute secure, co-signed transactions.
  • Create, store, and interact with tokens and NFTs.
  • Implement personal on-premise servers in conjunction with the BitGo Express package for secure interactions with the BitGo Platform.
  • Sign keys offsite and send transactional data confidently to BitGo APIs.

You have 2 options for installing the SDK:

  • Modular - Integrate only the coins you need.
  • All Coins - Integrate all coins that BitGo supports.

Note: BitGo recommends you implement a modular integration for the following benefits:

  • Better compatibility in resource-constrained environments (such as running in AWS lambda)
  • Reduce dependency exposure
  • Smaller install and memory footprint

Prerequisites

Core Packages

The following core packages enable you to integrate only the coins you need:

  • sdk-api - Main entry point for API functionality and for registering coins asynchronously.
  • sdk-coin-{name} - Implementation and dependencies necessary to interact with BitGo APIs and coin blockchains (such as mainnet, testnet, and any related tokens).

Steps

1. Install TypeScript

npm install -g typescript

2. Configure Your .env File

Create an .env file in the root directory of your project and add the following environment variables:

ACCESS_TOKEN=<YOUR_ACCESS_TOKEN>
ENV=test
WALLET_PASSPHRASE=<YOUR_LOGIN_PASSPHRASE>
ENTERPRISE_ID=<YOUR_ENTERPRISE_ID>
BITGO_EXPRESS_URL=<YOUR_LOCAL_HOST>

3. Install Dependencies

npm install axios zod cuid dotenv readline

4. Install Core Packages

# Main entry point for API functionality
npm install bitgo
# Main entry point for API functionality
npm install @bitgo/sdk-api
# Individual coin module
# For example, btc would be sdk-coin-btc
npm install @bitgo/sdk-coin-{name}

5. Use Core Packages

import { BitGo } from 'bitgo';
const sdk = new BitGo();
import { BitGoAPI } from '@bitgo/sdk-api';
import { Btc } from '@bitgo/sdk-coin-btc';
 
const sdk = new BitGoAPI();

# You must import testnet coins separately
# For example, `Tbtc4` instead of `Btc`
sdk.register('btc', Btc.createInstance);

6. Verify Your Installation

After installing the SDK, confirm it's working:

node -e "const BitGoJS = require('bitgo'); console.log('BitGo SDK loaded successfully');"

If you installed modularly:

node -e "const { BitGo } = require('@bitgo/sdk-core'); console.log('BitGo SDK Core loaded successfully');"

7. Run Your First SDK Script

Create a file called get-started.js and paste the following:

const BitGoJS = require('bitgo');

async function main() {
  const bitgo = new BitGoJS.BitGo({
    env: 'test',
    accessToken: process.env.BITGO_ACCESS_TOKEN,
  });

  // Verify authentication by fetching your user profile
  const user = await bitgo.me();
  console.log('Authenticated as:', user.username);
  console.log('User ID:', user.id);
}

main().catch(console.error);

Run it:

export BITGO_ACCESS_TOKEN="v2x..."
node get-started.js

Step Result

Authenticated as: [email protected]
User ID: 62ab90e06dfda30007974f0a52a12995

Next Steps

  1. Get notified about new releases by configuring your watch settings for the JavaScript SDK repo. Select Watch > Custom > Releases.
  2. Create Wallets.

See Also