public function testWalletSweep()
 {
     /*
      * We have set up a testnet wallet with known unspent outputs in certain addresses for this test
      */
     $increment = 10;
     //using a search increment of 10 for speed, as we know our funds are no more than 10 addresses apart from each other
     $primaryPassphrase = "password";
     $primaryMnemonic = "olive six drill desk jealous nice chronic draw reveal super already stick wear hurt aunt crazy step mechanic derive already kangaroo render tenant honey large cabin better guitar biology metal angry tide boat father slam title maple notice salmon shy mass shock dog cream twelve strong marble sudden";
     $backupMnemonic = "adapt finger below junk slam power opinion finish vapor measure code know stove mom confirm design chaos goat cradle mansion target fuel empty fox pill recycle brisk flush swap chimney dance mind brass moral stay shoulder slide shove march wise animal frame shed require alien moral onion auto";
     $blocktrailKeys = array(['keyIndex' => 0, 'path' => "M/0'", 'pubkey' => 'tpubD8UrAbbGkiJUmxDS9UxC6bvSGVd1vAEDMMkMBHTJ7xMMnkNuvBsVMQv6fXxAQgV3aaETetdaBBNQgULBzebM86MyYP526Ggqu8K8jPwBdP4'], ['keyIndex' => 9999, 'path' => "M/9999'", 'pubkey' => 'tpubD9q6vq9zdP3gbhpjs7n2TRvT7h4PeBhxg1Kv9jEc1XAss7429VenxvQTsJaZhzTk54gnsHRpgeeNMbm1QTag4Wf1QpQ3gy221GDuUCxgfeZ']);
     $bitcoinClient = new BlocktrailBitcoinService("MY_APIKEY", "MY_APISECRET", "BTC", true, 'v1');
     //create the wallet sweeper and do fund discovery
     $walletSweeper = new WalletSweeper($primaryMnemonic, $primaryPassphrase, $backupMnemonic, $blocktrailKeys, $bitcoinClient, 'btc', true);
     //$walletSweeper->enableLogging();    //can enable logging if test is taking too long or something seems to be wrong. NB: this test will take a long time - be patient
     $results = $walletSweeper->discoverWalletFunds($increment);
     $this->assertEquals(4, $results['count'], "expected utxo count to be 4");
     $this->assertEquals(40000000, $results['balance'], "unexpected balance amount");
     $this->assertGreaterThanOrEqual(50, $results['addressesSearched'], "expected at least 50 addresses to be searched");
     $this->assertEquals(3, count($results['utxos']), "expected 3 addresses to be found to have unspent outputs");
     $this->assertEquals(2, count($results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']['utxos']), "expected particular address to have 2 unspent outputs");
     $this->assertArrayHasKey('hash', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']['utxos'][0]);
     $this->assertArrayHasKey('index', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']['utxos'][0]);
     $this->assertArrayHasKey('value', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']['utxos'][0]);
     $this->assertArrayHasKey('script_hex', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']['utxos'][0]);
     $this->assertArrayHasKey('path', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']);
     $this->assertArrayHasKey('redeem', $results['utxos']['2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA']);
     //do fund sweeping - will carry out fund discovery if needed (already completed above) and then create and sign a transaction
     $destination = '2NA7zpiq5PcYUx6oraEwz8zPzn6HefSvdLA';
     $results = $walletSweeper->sweepWallet($destination, $increment);
     $this->assertArrayHasKey('hex', $results);
     $this->assertEquals('true', $results['complete']);
     $this->assertEquals(8, $results['req_sigs']);
     $this->assertEquals(8, $results['sign_count']);
 }
<?php

use Blocktrail\SDK\Services\BlocktrailBitcoinService;
use Blocktrail\SDK\WalletSweeper;
require_once __DIR__ . "/../vendor/autoload.php";
//Process can take a long time - disable php execution time limit
set_time_limit(0);
//the primary mnemonic, obtained from our backup pdf
$primaryMnemonic = "craft scatter train family grass bind sense double sample raven luxury\nvacant north limit swamp scatter warm core enable exist limit genius knee\nclutch document metal decline shaft canal utility powder earth later\nsymptom movie pluck traffic ozone power evoke spread gym habit legal cruel\nuniform fold high";
//our wallet passphrase
$primaryPassphrase = "example-strong-password";
//the primary mnemonic, obtained from our backup pdf
$backupMnemonic = "evil pill forum vault pelican method clever dwarf hurt morning survey core\nteach culture parade slam fee where flower climb silk piano ribbon pelican\ncandy genius battle entire lawn topic embark scheme heavy tackle proof\nsolution mimic crop average drama jar lava announce toy copper maid reduce\nhand";
//the blocktrail keys used by this wallet, obtained from the backup pdf
$blocktrailKeys = array(['keyIndex' => 0, 'path' => "M/0'", 'pubkey' => 'tpubD8UrAbbGkiJUmxDS9UxC6bvSGVd1vAEDMMkMBHTJ7xMMnkNuvBsVMQv6fXxAQgV3aaETetdaBBNQgULBzebM86MyYP526Ggqu8K8jPwBdP4'], ['keyIndex' => 9999, 'path' => "M/9999'", 'pubkey' => 'tpubD9q6vq9zdP3gbhpjs7n2TRvT7h4PeBhxg1Kv9jEc1XAss7429VenxvQTsJaZhzTk54gnsHRpgeeNMbm1QTag4Wf1QpQ3gy221GDuUCxgfeZ']);
//an instance of the bitcoin data service we want to use to search addresses for unspent outputs
$bitcoinClient = new BlocktrailBitcoinService("MY_APIKEY", "MY_APISECRET", "BTC", true, 'v1');
//create instance of sweeper - will automatically create primary keys from mnemonics
$walletSweeper = new WalletSweeper($primaryMnemonic, $primaryPassphrase, $backupMnemonic, $blocktrailKeys, $bitcoinClient, 'btc', $_testnet = true);
$walletSweeper->enableLogging();
//enable logging for more info
//Do wallet fund discovery - can be run separately from sweeping
//var_dump($walletSweeper->discoverWalletFunds());
//Do wallet fund discovery and sweeping - if successful you will be returned a signed transaction ready to submit to the network
$receivingAddress = "2NCcm7hJfJ5wk6GyKvT2ZHCrNsBgjBv2MSF";
$result = $walletSweeper->sweepWallet($receivingAddress);
var_dump($result);