Home/
Resources/
Training guide

Technical Training Guide

Your Guide to BitGo

USER AUTHENTICATION

Lock Session

Locks the current user session. This disallows operations that require an unlocked token, such as sending a transaction.

Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });

  bitgo.lock({}).then(function(lockResponse) {
    console.dir(lockResponse);
  });
})();

Unlock Session

Unlocks the current user session. This allows operations that require an unlocked token, such as sending a transaction.

Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });
  
  bitgo.unlock({otp: '0000000'}).then(function(lockResponse) {
    console.dir(lockResponse);
  });
})();

Get Session

This API call retrieves information about the current session access token.

You can use this API call if you’d like to verify the scope of your access token, which will include allowed scopes as well as the expiration date of the token and any associated unlocks.

Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.session({}, function callback(err, session) {
  if (err) {
    // handle error
  }
  console.dir(session);
  });
})();

Get User Profile

This API call retrieves information about the current authenticated user. You can use this API call as a sort of sanity test or if you use multiple users in your code.

Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.me({}, function callback(err, user) {
  if (err) {
    // handle error
  }
  // etc
    console.log(user);
  });
})();

Login

Creates a short-lived (1 hour) access token for use with the API. First-party access is only intended for users accessing their own BitGo accounts.

Input
User Authentication Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

const user = 'myExampleEmail@bitgo.com';
const password = 'secretpassword7e5s9s3i';

bitgo.authenticate({username: user, password: password, otp: '0000000'})
.then(function(response){
    
    console.dir(response);
});

Logout

Log out of the BitGo service. This will disable an access token.

Input
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.logout({})
.then(function() {
  // the user is now logged out
});

WALLET OPERATIONS

Create Wallet

All BitGo Wallets are multi-signature wallets comprised of N keys, and require M keys to sign a transaction before the transaction is valid. This is called an M-of-N wallet. BitGo currently supports only 2-of-3 wallets.

To create a wallet, 3 keychains must be provided. The first two keychains are provided and under control of the user; the last must be a BitGo keychain.

While BitGo can see the public portion of the first two keys, BitGo never has access to the private portion of these keys and therefore cannot conduct transactions without the user. The third BitGo key is not sufficient to sign transactions alone, and BitGo will only use this key in accordance with the policies set forth by the user.

This API call creates a new wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Open ‘create-wallet.js’
  3. Set your accessToken, coin of choice, walletLabel, and walletPassphrase
Input
Output
Copy
      const BitGoJS = require('../../../src/index.js');
      const bitgo = new BitGoJS.BitGo({ env: 'test' });
      const Promise = require('bluebird');

      // TODO: set your access token here
      const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
      // TODO: set your coin of choice
      const coin = 'tbtc';
      // TODO: set a label for your new wallet here
      const walletLabel = 'Final Wallet';
      // TODO: set your passphrase for your new wallet here
      const walletPassphrase = 'secretpassphrase8u7y6t5r';


      // Create the wallet
      Promise.coroutine(function *() {
        bitgo.authenticateWithAccessToken({ accessToken });

        const walletOptions = {
          walletLabel,
          walletPassphrase
        };

        const wallet = yield bitgo.coin(coin).wallets().generateWallet(walletOptions);
        const walletInstance = wallet.wallet;

        console.log(`Wallet ID: ${walletInstance.id()}`);
        console.log(`Receive address: ${walletInstance.receiveAddress()}`);
        console.log('BACK THIS UP: ');
        console.log(`User keychain encrypted xPrv: ${wallet.userKeychain.encryptedPrv}`);
        console.log(`Backup keychain xPrv: ${wallet.backupKeychain.prv}`);
      })();

Get Wallet by ID

This API call retrieves wallet object information by the wallet ID. This is useful to get the balance of the wallet, or identify the keys used to sign with the wallet using the Get Keychain API.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Open ‘get-wallet.js’
  3. Set your accessToken, coin of choice, and wallet ID
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d8dc8108066facc59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: get the wallet with this id
const walletId = '5d13ddd2ed50e8a603daa81970840e6e';

// Create the wallet with Bluebird coroutines
Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id:walletId });
  console.log(wallet._wallet);
})();

Get Wallet by Address

This API call retrieves wallet object information by an address belonging to the wallet. This is useful to get the balance of the wallet, or identify the keys used to sign with the wallet using the Get Keychain API.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-by-address.js’
  3. Set your accessToken, coin of choice, and walletAddress
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
// TODO: set your wallet ID here
let walletId = '5d115167da48898503f69c05e44391f1';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin('tbtc').wallets().get({ id: walletId })
    .then(function(wallet) {
        wallet.getAddress({address: '2N47pqyj8vCdQMsEtBiyCKJrg5HUvXwwkrk'})
        .then(function(address) {
          // print address
          console.dir(address);
        });
    });

})();

List Wallets

This API call lists all of a user’s wallets for a given coin. This is useful when you have over 500 wallets as you will not be able to use the Web UI.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-wallets.js’
  3. Set your accessToken and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallets = yield bitgo.coin(coin).wallets().list({});
  for (const wallet of wallets.wallets) {
    console.dir(`Wallet label: ${wallet.label()}`);
    console.dir(`Wallet ID: ${wallet.id()}`);
  }
})();

Send Transaction

This API call allows you to create and send cryptocurrency to a destination address.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, and destination address
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a14jg61dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae5824daa81970840e6e';
// TODO: set your wallet password here
const walletPassphrase = 'secretpassword7e5s9s3i'
// TODO: set your destination address here
const toAddress = '2MzkXNiej487ZrQhUNYuXEPa45QNWmv5o1n';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id : walletId })
 .then(function(wallet) {

    let params = {
        // TODO: set the amount you want to send here
        amount: 0.00005* 1e8,
        address: toAddress,
        walletPassphrase: walletPassphrase,
        sequenceId: "example"
    };

    wallet.send(params)
     .then(function(transaction) {
        console.dir(transaction);
    });
});

Send Transaction to Many

This API call allows you to create a transaction and send to multiple addresses. This may be useful if you schedule outgoing transactions in bulk, as you will be able to process multiple recipients and lower the aggregate amount of blockchain fees paid.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, and destination addresses
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your wallet passphrase here
const walletPassphrase = 'secretpassword7e5s9s3i';
// TODO: set your destination addresses here:
const destinationAddress1 = '2MwZ97N8F5ejKDUFJqkkeD8kzPSi1pucjAt';
const destinationAddress2 = '2N47pqyj8vCdQMsEtBiyCKJrg5HUvXwwkrk';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });

  const walletInstance = yield basecoin.wallets().get({ id: walletId });
  const transaction = yield walletInstance.sendMany({
    recipients: [
      {
        amount: '6000',
        address: receiveAddress1
      },
      {
        amount: '6000',
        address: receiveAddress2
      }
    ],
    walletPassphrase: walletPassphrase
  });
  const explanation = basecoin.explainTransaction({ txHex: transaction.tx });

  console.log('Wallet ID:', walletInstance.id());
  console.log('Current Receive Address:', walletInstance.receiveAddress());
  console.log('New Transaction:', JSON.stringify(transaction, null, 4));
  console.log('Transaction Explanation:', JSON.stringify(explanation, null, 4));
})();

Get Wallet Balance

This API call retrieves wallet object information by the wallet ID. This is useful to get the balance of the wallet, or identify the keys used to sign with the wallet using the Get Keychain API.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-balance.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
// TODO: set your coin of choice here
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your wallet Id here
const walletId = '5d115167da48898503f69c05e44391f1';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });

  const walletInstance = yield basecoin.wallets().get({ id: walletId });
  console.log('Wallet ID:', walletInstance.id());
  console.log('Current Receive Address:', walletInstance.receiveAddress());
  console.log('Balance:', walletInstance.balanceString());
  console.log('Confirmed Balance:', walletInstance.confirmedBalanceString());
  console.log('Spendable Balance:', walletInstance.spendableBalanceString());
})();

Get Wallet Transfer

Wallet transfers represent digital currency sends and receives on your wallet. This is the recommended method to track funding withdrawals and deposits.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-transfer.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet id here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO = set your transaction ID
const txId = '813cd20a7cfd43efffeb3916983b2a854a1077054ff051a8af8192529eaccc05';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId});
  wallet.getTransfer({ id: txId })
  .then(function(transfer) {
    console.dir(transfer);
  });
})();

Get Wallet Transfer by Sequence

Get the transaction on a wallet sequence ID that was passed in when sending a transaction (via Send Transaction or Send Transaction to Many). This is useful for tracking an unsigned/unconfirmed transaction via your own unique ID, as coin transaction IDs are not defined before co-signing.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-transfer.js’
  3. Set your accessToken, coin of choice, walletId, and sequenceId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of chocie here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your sequence ID here
let sequenceId = 'example';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId});


    wallet.transferBySequenceId({ sequenceId: sequenceId })
    .then(function(transfer) {
        // print the transfer object
        console.dir(transfer);
    });
})();

Create Wallet Address

This API call is used to create a new receive address for your wallet, which enhances your privacy. You may choose to call this API whenever a deposit is made.

Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc'
// TODO: get the wallet with this id
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
//TODO: set address label
const addressLabel = 'My address'

bitgo.authenticateWithAccessToken({ accessToken: accessToken });
bitgo.coin(coin).wallets().get({ id: walletId }, function callback(err, wallet) {
  if (err) {
    throw err;
  }
  wallet.createAddress({ label: addressLabel }).then(function(address){
    console.dir(address)
  })
});

List Wallet Transfers

Returns deposits and withdrawals for a wallet. Transfers are sorted in descending order by height, then ID.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-wallet-transfers.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
const basecoin = bitgo.coin(coin);
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });

  const walletInstance = yield basecoin.wallets().get({ id: walletId });
  const transfers = yield walletInstance.transfers();

  console.log('Wallet ID:', walletInstance.id());
  console.log('Current Receive Address:', walletInstance.receiveAddress());
  console.log('Wallet Transactions:', JSON.stringify(transfers, null, 4));
})();

Get Wallet Address

This API call is used to get information about a single wallet address. The address object can be fetched by using either the ID or the address itself.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-address.js’
  3. Set your accessToken, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your wallet address here
const walletAddress = '2N47pqyj8vCdQMsEtBiyCKJrg5HUvXwwkrk';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin('tbtc').wallets().get({ id: walletId })
    .then(function(wallet) {
        wallet.getAddress({address: walletAddress})
        .then(function(address) {
          // print address
          console.dir(address);
        });
    });

})();

Get Fee Estimate

Returns the estimated fee for a transaction. UTXO coins will return a fee per kB, while Account-based coins will return a flat fee estimate.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-fee-estimate.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });
  bitgo.coin(coin).feeEstimate({ numBlocks: 2 }, function callback(err, res) {
     console.dir(res);
  });
})();

Resend Wallet Share Invitation

Resends the wallet share invitation to the share recipient. The wallet share must not have been accepted yet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-fee-estimate.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: get the wallet with this id
const shareId = '5d40a36c466d2c7203985c8ab01f5e8f';

// Create the wallet with Bluebird coroutines
Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin('tbtc').wallets().resendShareInvite({ walletShareId: shareId })
  .then(function(share) {
    console.dir(share);
  });
})();

Calculating Mining Fees

Calculate the fee and estimated size in bytes for a Bitcoin transaction.

Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });
let params = {
    feeRate: 50000,
    nP2shInputs: 2,
    nP2pkhInputs: 0,
    nP2shP2wshInputs: 1,
    nOutputs: 2
}

let results = bitgo.calculateMinerFeeInfo(params)
  .then(function(feeInfo){
    console.log(feeInfo);
  });

ADVANCED WALLET OPERATIONS

List Wallet Addresses

This API call is used to retrieve a wallet’s addresses. This covers all receive addresses, including both external and change addresses.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-wallet-addresses.js’
  3. Set your accessToken, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your walletID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
    wallet.addresses()
    .then(function(addresses) {
      // print addresses
      console.dir(addresses);
    });
});

Get Total Balances

This API call will calculate the total balance across all wallets with the specified coin type. The resulting total balance is broken down into three categories: balance, confirmed balance, and spendable balance.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-total-balances.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
      const BitGoJS = require('../../../src/index.js');
      const bitgo = new BitGoJS.BitGo({ env: 'test' });

      // TODO: set your access token here
      const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
      // TODO: set your coin of choice
      const coin = 'tbtc';

      bitgo.authenticateWithAccessToken({ accessToken });
      bitgo.coin(coin).wallets().getTotalBalances()
      .then(function (balances) {
        // print total balances across all wallets for this coin
        console.dir(balances);
      });

Get Maximum Spendable

This API call will retrieve the maximum amount that can be spent with a single transaction from the wallet. The maximum spendable amount can differ from a wallet’s total balance.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-maximum-spendable.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({id: walletId})
.then(function (wallet) {
    wallet.maximumSpendable().then(function(amount) {
      // print maximum spendable amount
      console.dir(amount);
    });
});

Get Unspents

This API call will retrieve the unspent transaction outputs (UTXOs) within a wallet. This may be relevant if you are trying to do manual coin control when operating an unspent-based blockchain such as Bitcoin.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-unspents.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({id: walletId})
.then(function (wallet) {
    wallet.unspents()
    .then(function(unspents) {
      // print unspents
      console.dir(unspents);
    });
});

Consolidate Wallet Unspents

Consolidate unspents on a wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘consolidate-wallet-unspents.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your walletID here
let walletId = '5d115167da48898503f69c05e44391f1';

let params = {
    numUnspentsToMake: 1,
    minValue: 100000,
    maxValue: 47000000,
    minHeight: 1,
    minConfirms: 2,
    limit: 100,
    walletPassphrase: '8pIbA0bz%CyJ3X!18$S0l'
};

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
    wallet.consolidateUnspents(params)
    .then(function(transactionInfo) {
      // print transaction info
      console.dir(transactionInfo);
    });
});

Fanout Unspents

This SDK call will fanout the unspents currently in the wallet that match the parameters, and use them as inputs to create more unspents.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘fanout-unspents.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
let walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your wallet passphrase here
const walletPassphrase = 'secretpassword7e5s9s3i';

let params = {
    maxNumInputsToUse: 20,
    numUnspentsToMake: 200,
    minValue: 100000,
    maxValue: 47000000,
    minHeight: 1,
    minConfirms: 2,
    walletPassphrase: walletPassphrase
};

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
    wallet.fanoutUnspents(params)
        .then(function(transactionInfo) {
    console.dir(transactionInfo);
    });
});

Sweep

This call attempts to move all of the funds of the wallet into the address provided.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘sweep.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, and destination address
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your wallet password
const walletPassphrase = 'secretpassword7e5s9s3i';
// TODO: set your destination address
const toAddress = '2MzkXNiej487ZrQhUNYuXEPa45QNWmv5o1n';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id: walletId })
 .then(function(wallet) {
 
 let params = {
    address: toAddress,
    walletPassphrase: walletPassphrase
};

  wallet.sweep(params)
    .then(function(transactionInfo) {
  // print transaction info
  console.dir(transactionInfo);
});
});

Build Transaction

Create a transaction with the specified parameters. This builds a transaction object, but does not sign or send it.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘build-transaction.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, and destination address
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your destination address
const toAddress = '2MzkXNiej487ZrQhUNYuXEPa45QNWmv5o1n';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id: walletId })
 .then(function(wallet) {
 
    let params = {
      recipients: [
        {
          amount: 0.001 * 1e8,
          address: toAddress,
        }
      ]
    };
    wallet.prebuildTransaction(params)
    .then(function(transaction) {
      // print transaction details
      console.log(transaction); 
    });
});

Sign Transaction

Sign the given transaction with the specified keychain. All signing is done locally and can be performed offline.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘sign-transaction.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, and build parameters
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d23a55eeb8f1b7603d6f4974db9ba1d';
// TODO: set your destination address
const toAddress = '2N5RnGSD7WaZD4AfULDcqJopHQWGmkY6Hj7';
// TODO: set your build parameters here
const buildParams = { recipients: [{ amount: 3000, address: toAddress}] };

bitgo.authenticateWithAccessToken({ accessToken });

//TODO: set your encrypted User Key from your Key Card
var encryptedString = '{"iv":"G3LdrjBiadeyP1bpHjtGkA==","v":1,"iter":10000,"ks":256,"ts":64,"mode":"ccm","adata":"","cipher":"aes","salt":"as3BU1c/Hvc=","ct":"BfbmGepxQwDqCXCMDrF7th4F+rMLSQzdOgKP8rl07116Wds05z6yABHnEVjZa4OxHrm1ZD+FGwbnB8clAEpbOZG67isgvCgLPFM/nVtpAkpuQbkOr++EqZgy6cax182s1SBPNgvrpfER+MTHHG8HZ94v9OtMQRY="}';
var decryptedString = bitgo.decrypt({ password: "scientology", input: encryptedString });
bitgo.coin(coin).wallets().get({ id: walletId }).then(function(wallet) {

    wallet.prebuildTransaction(buildParams).then(function(transaction){
        wallet.signTransaction({ txPrebuild: transaction, prv: decryptedString })
       .then(function(transaction) {
        //print half-signed transaction hex
            console.dir(transaction);
        }); 
    });
});

Send Transaction

Submit a half-signed transaction. The server will do one of the following: apply the final signature and submit to the Bitcoin P2P network, gather additional approvals from other wallet admins, or reject the transaction altogether.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2x57e2a561bdd5467483497837e4cad4a01ca296cdaf0009b3fb4927bdaad6d02c';
// TODO: set your coin of choice
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId = '5d4a2a7532ca67940389f47a703c2180';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id: walletId })
 .then(function(wallet) {
 
 let params = {
  txHex: "0100000001016e9782c5355e4a2cfb8aa06954365b607493d44aba985e5c714ea277d521680000000000ffffffff02a08601000000000017a914e2a1f3d2f1fa3a9f269b747a9a725a92fc40340387e01606000000000017a91491b2aac61ddea32ca02ac093fd16ad93fb575ac1871b001800",
  otp: '0000000'
};
wallet.submitTransaction(params)
.then(function(transaction) {
  // print transaction status
  console.dir(transaction);
});
});

Change Fee on Transaction

This API call will change the fee rate on the transaction specified by transaction ID in the request. Currently, this feature only applies to ETH and ERC-20 tokens, requires the fee to be increased by a minimum amount of 10 Gwei, and at least one hour has passed since the transaction was first sent.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘change-fee-on-transaction.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'terc';
// TODO: set your address here
const walletAddress = '0xecf99db857c2519dcb00d58861627caefa215164';
// TODO: set your transaction ID of the stuck transaction here
const txid = "0x1a01bb28abe25929a6c0cabf2a86e2b806f1fc17219708a6351bec5e36625f4f";
// TODO: set the new fee
const newFee = "150000000000";

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().getWalletByAddress({ address: walletAddress })
 .then(function(wallet) {
    wallet.changeFee({txid: txid, fee: newFee})
    .then(function(newTxHash) {
      // print the txHash of the updated transaction
      console.dir(newTxHash);
    })
});

CPFP

Send a child-pays-for-parent (CPFP) transaction to accelerate the target unconfirmed transactions.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘CPFP.js’
  3. Set your accessToken, walletId, walletPassphrase, stuckTxId, an OTP, and your newFeeRate
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// The wallet calling this needs to be the one receiving the transaction
// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
var coin = 'tbtc';
// TODO: set your wallet ID here
var walletId = '5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your wallet password here
var walletPassphrase= 'secretpassword7e5s9s3i';
// TODO: set the transaction ID of the stuck transaction here
var stuckTxId = '37df6e74a4a992b26377dc367b8a0f86f6225f16cf0b8c5aff9af390fe506b92';
// TODO: set new fee rate for the stuck transaction (satoshis per 1000 bytes)
var newFeeRate = 30000;

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id: walletId }, function(err, wallet) {
    const input = 
    {
    cpfpTxIds: [
        stuckTxId
    ],
    cpfpFeeRate: newFeeRate,
    maxFee: 4000000,
    walletPassphrase: walletPassphrase
    }
    if (err) {
      console.dir(err);
      throw new Error("Could not unlock!");
    }
    wallet.accelerateTransaction(input, function(err, result) {
      if (err) {
        console.dir(err);
      }
        console.dir(result);
    });
 });

Add Wallet

This method is for advanced API users and allows manual creation and specification of keys. In the SDK or BitGo Express, Generate Wallet is the simpler and highly recommended method to create a wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘add-wallet.js’
  3. Set your accessToken, coin of choice, and walletLabel
Input
Output
Copy
const BitGoJS = require('bitgo');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
//ORDER OF KEYS: USER KEY, BACKUP KEY, BITGO KEY

// Set your access token here
const accessToken = 'v2xcbe8617bd82423a9ec41cc7aaoe849a9d81dc2780669fa83ab439ac6ad5792da';
// Set your coin of choice here
const coin = 'tbtc';
// Set a label for your new wallet here
const walletLabel = 'Example Wallet';

// Create the wallet
Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin(coin).wallets()
  .add({
    isCold: true,
    label: walletLabel,
    m: 2,
    n: 3,
    //Set your User Key, Backup Key, and BitGo Key here
    keys: [
      "5d6853ba1fff627403208a41813cf8bb",
      "5d68549e4d3d4d7503111ac47cc7e85d",
      "5d6854e602ea7c6c037fe63974515427"
    ]
  })
  .then(function(wallet) {
    // print the new wallet
    console.dir(wallet);
  });
})();

Create Advanced (Cold) Wallet

Creates a cold wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-cold-wallet.js’
  3. Set your accessToken, coin of choice, and walletLabel
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');
//ORDER OF KEYS: USER KEY, BACKUP KEY, BITGO KEY

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set a label for your new wallet here
const walletLabel = 'Example Wallet';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin(coin).wallets()
  .add({
    label: walletLabel,
    m: 2,
    n: 3,
    keys: [
      "5d4cbeea1de74d55039f3b65bafa1345",
      "5d4cbfef2232fa5c039e7be69851300a",
      "5d4cc05d264961950397f5e74ac5bded"
    ],
    isCold: true,
    enterprise: "5d31296b5e9ba67e03279c7aeb8bc71b"
  })
  .then(function(wallet) {
    // print the new wallet
    console.dir(wallet);
  });
})();

Create Custodial Wallet

Creates a custodial wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-cold-wallet.js’
  3. Set your accessToken, coin of choice, and walletLabel
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// Set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// Set your coin of choice here
const coin = 'tbtc';
// Set a label for your new wallet here
const label = 'Example Wallet';

// Create the wallet
Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  bitgo.coin(coin).wallets()
  .add({
    label: label,
    enterprise: "5d3a3b9f99bbff72035bb3c442766dcb",
    type: "custodial"
  })
  .then(function(wallet) {
    // print the new wallet
    console.dir(wallet);
  });
})();

KEYCHAINS

List Keychains

Retrieve a keychain based on its key id. To find out the key IDs, use the List Keys API or the Get Wallet API.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-keychains.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = ‘v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae’;
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).keychains().list()
.then(function(keychain) {
  // print the keychains
  console.dir(keychain);
});

Get Keychain

Retrieve a keychain based on its key ID. To find key IDs, use the List Keys API or the Get Wallet API.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-keychain.js’
  3. Set your accessToken, coin of choice, and keyId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set a key id here
let keyId = '5d40aba84002d78803aaa63b017832d4';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).keychains().get({ id: keyId })
.then(function(keychain) {
  // print the keychain
  console.dir(keychain);
});

Create Keychain

Local client-side function to create a new keychain. The created keychain is not known to the BitGo service. To use it with the BitGo service, use the ‘Store Keychain’ API call.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-keychain.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });
let key = bitgo.coin(coin).keychains().create();
console.dir(key);

Create BitGo Keychain

Creates a new keychain on BitGo’s servers and returns the public keychain to the caller.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-bitgo-keychain.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).keychains().createBitGo()
.then(function(keychain) {
  // print the keychain
  console.dir(keychain);
});

Create Backup Keychain

Creates a new backup keychain on a third party specializing in key recovery services. This keychain will be stored on the third party service and usable for recovery purposes only.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-backup-keychain.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).keychains().createBackup({ provider: 'dai' })
.then(function(keychain) {
  // print the keychain
  console.dir(keychain);
});

Add Keychain

This API call allows you to add a public keychain on BitGo’s server. Only the public key parameter is required.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘add-keychain.js’
  3. Set your accessToken, and coin of choice
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';

bitgo.authenticateWithAccessToken({ accessToken });

let key = {
pub:
   'xpub661MyMwAqRbcFnCEpKaE3sejZzMkcrZ91ewrAHQsJEU1pHUEXu4tmMRRmAxYnfguT8d9wTSrSygMatSC4E9fTnkwcKv87LwF2s67j2Hiviw'};

bitgo.coin(coin).keychains().add(key)
.then(function(keychain) {
  // print the keychain
  console.dir(keychain);
});

WALLET POLICY

Get Wallet Policy

Gets the list of policies in operation on a wallet is included when the wallet is fetched.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-wallet-policy.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
//TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: get the wallet with this id
const walletId = '5d13ddd2ed50ae9603daa81970840e6e';


// Create the wallet with Bluebird coroutines
Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId });

  console.dir(wallet._wallet.admin.policy);

})();

Create Policy

Adds a rule to a wallet’s policy. A wallet policy’s rules control the conditions under which BitGo will use its single key to sign a transaction.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘create-policy.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId });

  console.log(`Setting new velocity limit policy on wallet ${wallet.label()}`);
  const policy = {
    action: {
      type: 'getApproval'
    },
    condition: {
      add: '2N7jDsDaGtZd2p6wb8anxsEZD5Zq2HBfWTT'
    },
    id: 'test_policy',
    type: 'coinAddressWhitelist'
  };

  const result = yield wallet.createPolicyRule(policy);
  console.dir(result);
})();

Update Policy

Update a rule on a wallet’s policy.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘update-policy.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet Id here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId });

  console.log(`Setting new velocity limit policy on wallet ${wallet.label()}`);

  const policy = {
    action: {
      type: 'getApproval'
    },
    condition: {
      add: '2N7jDsDaGtZd2p6wb8anxsEZD5Zq2HBfWTT'
    },
    id: 'test_policy',
    type: 'coinAddressWhitelist'
  };

  const result = yield wallet.setPolicyRule(policy);
  console.dir(result);
})();

Delete Policy

Remove a policy rule with the specified ID. This may require a secondary approval if there is more than 1 “admin” user on the wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘delete-policy.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet Id here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken });

  const wallet = yield bitgo.coin(coin).wallets().get({ id: walletId });

  const policy = {
    action: {
      type: 'getApproval'
    },
    condition: {
      remove: '2N9oR6Po2ei9iyTrFtnbwZp9pDkuuCbZS98'
    },
    id: 'Example_Policy',
    type: 'coinAddressWhitelist'
  };

  const result = yield wallet.removePolicyRule(policy);
  console.dir(result);
})();

PENDING APPROVAL

Get Pending Approval

This API calls retrieves the object information for a pending approval by ID.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘get-pending-approval.js’
  3. Set your accessToken, coin of choice, walletId, and pendingApprovalId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your pending approval ID here
const pedningApprovalId ='5d4098459a9af27d0322792a3cc40736';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).pendingApprovals().get({id: pedningApprovalId})
.then(function(pendingApproval) {
  console.dir(pendingApproval._pendingApproval);
});

List Pending Approval

List pending approvals on a wallet or an enterprise by providing either a wallet ID or an enterprise in the url. By default, the request returns all the pending approvals for a user.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-pending-approvals.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).pendingApprovals().list({walletId})
.then(function(list) {
  // Print approval list
  console.dir(list.pendingApprovals);
});

WEBHOOK NOTIFICATIONS

List Block Webhooks

List webhooks set up on the wallet. Currently, the types of webhooks that can be attached to a wallet are transfer, pendingapproval, and address_confirmation notifications.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('bitgo');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd82423a9ec41cc7aaoe849a9d81dc2780669fa83ab439ac6ad5792da';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';


bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
  return wallet.listWebhooks();
})
.then(function(webhooks) {
  console.dir(webhooks);
});

Add Wallet Webhook

Add a webhook that will result in an HTTP callback at the specified URL from BitGo when events are triggered. There is a limit of 10 webhooks of each type per wallet.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘add-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your url
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your url here
const url = "http://your.server.com/webhook";

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).wallets().get({ id: walletId })
.then(function(wallet) {
  return wallet.addWebhook({
    url: url,
    type: "transfer"
  });
})
.then(function(webhook) {
  // print the new webhook
  console.dir(webhook);
});

Remove Wallet Webhook

Removing a webhook will cause new events of the specified type to no longer trigger HTTP callbacks to your URLs.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘remove-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your url
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your url here
const url = "http://your.server.com/webhook";

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
  return wallet.removeWebhook({
    url: url,
    type: "transfer"
  });
})
.then(function(result) {
  console.dir(result);
});

Simulate Wallet Webhook

Simulates and tests a webhook so you can view its response. A transferId or pendingApprovalId is required.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘remove-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your url
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').wallets().get({ id: walletId })
.then(function(wallet) {
    wallet.simulateWebhook({
    webhookId: '5d3a3209a1e7f37103f54ee99707459b',
    transferId: '5d3b3a5cc660c3670352f164c0f43e57'
  })
  .then(function(result) {
    console.dir(result);
  });
});

List Wallet Block Webhooks

Returns block webhooks. The types of webhooks are block and wallet_confirmation notifications.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘list-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, and walletId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';


bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).webhooks().list()
.then(function(result) {
  console.dir(result);
});

Add Wallet Block Webhook

Adds a webhook that will result in an HTTP callback at the specified URL from BitGo when events are triggered.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘add-block-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your url
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your label here
const label = "Example_Label";
// TODO: set your url here
const url = "http://your.server.com/webhook";

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).webhooks().add({
  url: url,
  type: "block",
  label: label,
  numConfirmations: 1
})
.then(function(result) {
  console.dir(result);
});

Remove Wallet Block Webhook

Removing a webhook will cause new events of the specified type to no longer trigger HTTP callbacks to your URLs.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘remove-wallet-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your url
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';
// TODO: set your url here
const url = "http://your.server.com/webhook";

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin('tbtc').webhooks().remove({
  url: url,
  type: "block"
})
.then(function(result) {
  console.dir(result);
});

Simulate Wallet Block Webhook

Simulates and tests a block webhook so you can view its response.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘simulate-block-webhooks.js’
  3. Set your accessToken, coin of choice, walletId, and your blockId
Input
Output
Copy
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });

//block ID can be found https://testnet.smartbit.com.au/blocks
// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'tbtc';
// TODO: set your wallet ID here
const walletId ='5d13ddd2ed50ae9603daa81970840e6e';

bitgo.authenticateWithAccessToken({ accessToken });
bitgo.coin(coin).webhooks().simulate({
  webhookId: '5d3a30c0c8dbf0720303f7d295ac3447',
  blockId: '00000000000001e84f79410333d714a3012ecc6ad42352b3e4aef4ae63671d9b'
})
.then(function(result) {
  console.dir(result);
});

OTHER CURRENCIES

Send Stellar

Sends stellar transactions.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-stellar.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, destinationAddress, and amount
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
// TODO: set your coin of choice here
const coin = 'txlm';
// TODO: set your wallet ID here
const walletId = '5d31231510c9427903da61412b6f9bee';
// TODO: set your passphrase here
const walletPassphrase = '8pIbA0bz%CyJ3X!18$S0l';
// TODO: set your destination address here
const destinationAddress = 'GCMIU4YH2DJSXOELDOV7WPEVLGWVUIF7VCMNTRMYIPAZWMIOXK2VZVZI';
// TODO: set the amount you want to send here
const amount = 1000;

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });

  bitgo.coin(coin).wallets().get({ id: walletId })
 .then(function(wallet) {
  let params = {
    amount: amount+'',
    address: destinationAddress,
    walletPassphrase: walletPassphrase
  };
  wallet.send(params)
   .then(function(transaction) {
    console.log(JSON.stringify(transaction, null, 1));
    //console.dir(transaction);
  });

});
})();

Send Ripple

Sends ripple transactions.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction-xrp.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, destinationAddress, and amount
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
//TODO: set your coin of choice here
const coin = 'txrp';
// TODO: set your wallet ID here
const walletId = '5d31281e626c2a6f0382e5b15bfb6c1c';
// TODO: set your passphrase here
const walletPassphrase = '8pIbA0bz%CyJ3X!18$S0l';
// TODO: set your destination address here
const destinationAddress = 'r9Z7NxfaHKaPoYjSryStUyBHBxjYKdyo6M?dt=0';
// TODO: set the amount you want to send here
const amount = 1;

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });
  bitgo.coin(coin).wallets().get({ id: walletId })
 .then(function(wallet) {
  let tmpAmount = amount;
  let params = {
    amount: amount+'',
    address: destinationAddress,
    walletPassphrase: walletPassphrase
  };
  wallet.send(params)
   .then(function(transaction) {
    console.log(JSON.stringify(transaction, null, 1));
    //console.dir(transaction);
  });
  });
})();

Send Ether

Sends ether transactions.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction-eth.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, destinationAddress, and amount
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
//TODO: set your coin of choice here
const coin = 'teth';
// TODO: set your wallet ID here
const walletAddress= '0x371e1b197bed15fcdaec511d70448e8549b989b1';
// TODO: set your passphrase here
const walletPassphrase = '8pIbA0bz%CyJ3X!18$S0l';
// TODO: set your destination address here
const destinationAddress = '0xecf99db857c2519dcb00d58861627caefa215164';
// TODO: set the amount you want to send here
const amount = '1000';

Promise.coroutine(function *() {
  bitgo.authenticateWithAccessToken({ accessToken: accessToken });
  bitgo.coin(coin).wallets().getWalletByAddress({ address: walletAddress })
 .then(function(wallet) {
  let params = {
    amount: amount,
    address: destinationAddress,
    walletPassphrase: walletPassphrase
  };
  wallet.send(params)
   .then(function(transaction) {
    console.log(JSON.stringify(transaction, null, 1));
    //console.dir(transaction);
  });
});
})();

Send ERC-20

Sends ERC-20 transactions.

Steps

  1. In your file explorer go to BitGoJS/modules/core/example/v2
  2. Create a file and name it ‘send-transaction-erc.js’
  3. Set your accessToken, coin of choice, walletId, walletPassphrase, destinationAddress, and amount
Input
Output
Copy
const BitGoJS = require('../../../src/index');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const Promise = require('bluebird');

// TODO: set your access token here
const accessToken = 'v2xcbe8617bd58947a9ec41cc7a92e0a9a9d81dc2780669faa59eab3016ad5792ae';
//TODO: set your coin of choice here
const coin = 'terc';
// TODO: set your wallet ID here
const walletId= '5d31f46632c6f07d0312ee6f4f554a08';
// TODO: set your passphrase here
const walletPassphrase = '8pIbA0bz%CyJ3X!18$S0l';
// TODO: set your destination address here
const destinationAddress = '0x371e1b197bed15fcdaec511d70448e8549b989b1';
// TODO: set the amount you want to send here
const amount = '1';

Promise.coroutine(function *() {
bitgo.authenticateWithAccessToken({ accessToken: accessToken });
bitgo.coin(coin).wallets().get({ id: walletId })
.then(function(wallet) {
    let params = {
    amount: amount+'',
    address: destinationAddress,
    walletPassphrase: walletPassphrase,
};
wallet.send(params)
.then(function(transaction) {
 console.log(JSON.stringify(transaction, null, 1));
 //console.dir(transaction);
});

});
})();