BitGo Wallet Creation and Coin Sending Guide

In this guide you’ll see how you can use BitGo’s SDK to create two wallets on testnet and send coins from one wallet to the other. You’ll first need to install nodejs and the Bitgo SDK, which you can see how to do at the Installation Guide. And, if you don’t already have a BitGo API access token on testnet, check out the Authentication Guide before continuing with this guide.

Authenticate using your API Access Token

var BitGoJS = require('bitgo'); var bitgo = new BitGoJS.BitGo({ env: 'test', accessToken: process.env.ACCESS_TOKEN });

Be sure to include this authentication code snippet before each block of code below, or your request will not be authenticated! Try creating a wallet with the code snippet below

Create a wallet

var wallet; bitgo.wallets().createWalletWithKeychains({ passphrase: 'replaceme', label: 'mywallet' }, function(err, result) { wallet = result.wallet.wallet; console.dir(wallet); var userKeychain = result.userKeychain; var backupKeychain = result.backupKeychain; console.dir(userKeychain); console.log('\n'); console.dir(backupKeychain); });

You now need to fund your wallet with testnet coin, which you can do my using this bitcoin faucet. For your receive address use the value of the “id” key from the userKeychain object we just created. You can check if you’ve received coins from the testnet faucet by running the code snippet below (just replace the address ‘2MzqD…’ which your own address).

Check wallet balance

bitgo.wallets().get({ type: 'bitcoin', id: '2MzqDLU9phkpZLDQRm7Hz7i14ytaT6AWsFt' }, function(err, wallet) { console.log('Wallet balance: ' + wallet.balance() + ' satoshis'); });

Finally, create a second wallet which you’ll use to receive coins sent from your first wallet. Assuming the id of this second wallet is “2N3N8QureVEQEBd8xSzmQ3jFyDKA773JxUJ” use the following code snippet to send 0.02 bitcoins from your first wallet to the second.

bitgo.wallets().get({ type: 'bitcoin', id: '2MzqDLU9phkpZLDQRm7Hz7i14ytaT6AWsFt' }, function(err, wallet) { wallet.sendCoins({ address: '2N3N8QureVEQEBd8xSzmQ3jFyDKA773JxUJ', amount: 2000000, walletPassphrase: 'replaceme', minConfirms: 0 }, function(err, result) { console.dir(result); } ); });