<?php use Blocktrail\SDK\BackupGenerator; use Blocktrail\SDK\BlocktrailSDK; require_once __DIR__ . "/../vendor/autoload.php"; $client = new BlocktrailSDK("MY_APIKEY", "MY_APISECRET", "BTC", true, 'v1'); $client->setVerboseErrors(true); //create a new wallet $bytes = openssl_random_pseudo_bytes(10); $identifier = bin2hex($bytes); list($wallet, $primaryMnemonic, $backupMnemonic, $blocktrailPublicKeys) = $client->createNewWallet($identifier, "example-strong-password", $_account = 9999); //generate the backup document $backupGenerator = new BackupGenerator($primaryMnemonic, $backupMnemonic, $blocktrailPublicKeys); $pdfStream = $backupGenerator->generatePDF(); //we can either save the pdf file locally file_put_contents("my wallet backup.pdf", $pdfStream); //or output the pdf to the browser header("Content-type:application/pdf"); echo $pdfStream; //html and img documents can also be generated for saving/returning to the browser //$backupHTML = $backupGenerator->generateHTML(); //echo $backupHTML; //$backupGenerator->generateImg('my wallet backup.png'); //save image to disk //$backupGenerator->generateImg(); //stream image to browser
<?php use Blocktrail\SDK\BlocktrailSDK; use Blocktrail\SDK\Connection\Exceptions\ObjectNotFound; use Blocktrail\SDK\Wallet; use Blocktrail\SDK\WalletInterface; require_once __DIR__ . "/../vendor/autoload.php"; $client = new BlocktrailSDK("MY_APIKEY", "MY_APISECRET", "BTC", true, 'v1'); $client->setVerboseErrors(); // $client->setCurlDebugging(); /** * @var $wallet \Blocktrail\SDK\WalletInterface * @var $backupMnemonic string */ try { /** @var Wallet $wallet */ $wallet = $client->initWallet(["identifier" => "example-wallet", "passphrase" => "example-strong-password"]); } catch (ObjectNotFound $e) { list($wallet, $primaryMnemonic, $backupMnemonic, $blocktrailPublicKeys) = $client->createNewWallet(["identifier" => "example-wallet", "passphrase" => "example-strong-password", "key_index" => 9999]); $wallet->doDiscovery(); } var_dump($wallet->getBalance()); var_dump(count($wallet->utxos())); $max = $wallet->getMaxSpendable(true); var_dump($max); var_dump($wallet->pay([$wallet->getNewAddress() => $max['max']], null, true)); sleep(2); var_dump(count($wallet->utxos()));