<?php

// # Derive New Address in a HD Wallet
//
// This sample code demonstrate how you can derive new addresses in a hd wallet,
// as documented here at <a href="http://dev.blockcypher.com/#derive-address-in-wallet-endpoint">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/Wallet-Name/addresses/derive
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    /// Generate new address
    $output = $walletClient->deriveAddress($walletName);
} catch (Exception $ex) {
    ResultPrinter::printError("Derive Address in a HDWallet", "HDWallet", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Derive Address in a HDWallet", "HDWallet", $walletName, null, $output);
return $output;
示例#2
0
<?php

// # Get HDWallet
//
// This sample code demonstrate how you can get a HD wallet, as documented here at
// <a href="http://dev.blockcypher.com/#wallets">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/HDWallet-Name
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    $output = $walletClient->get($walletName);
} catch (Exception $ex) {
    ResultPrinter::printError("Get a HDWallet", "HDWallet", null, $walletName, $ex);
    exit(1);
}
ResultPrinter::printResult("Get a HDWallet", "HDWallet", $output->getName(), null, $output);
return $output;
示例#3
0
<?php

// # Delete HDWallet
//
// This sample code demonstrate how you can delete a HD wallet, as documented here at
// <a href="http://dev.blockcypher.com/#delete-wallet-endpoint">docs</a>
//
// API used: DELETE /v1/btc/main/wallets/hd/Wallet-Name
require __DIR__ . '/../bootstrap.php';
// Delete a new instance of HDWallet object.
// First you have to run CreateHDWallet sample to create "bob" wallet
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    /// Delete the HDWallet
    $output = $walletClient->delete($walletName);
} catch (Exception $ex) {
    ResultPrinter::printError("Deleted HDWallet", "HDWallet", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Deleted HDWallet", "HDWallet", $walletName, null, $output);
return $output;
<?php

// # Generate New Address in a HD Wallet
//
// This sample code demonstrate how you can generate new addresses in a hd wallet,
// as documented here at <a href="http://dev.blockcypher.com/#generate-address-in-wallet-endpoint">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/Wallet-Name/addresses/generate
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    /// Generate new address with subchain_index
    $params = array('subchain_index' => 1);
    $output = $walletClient->generateAddress($walletName, $params);
} catch (Exception $ex) {
    ResultPrinter::printError("Generate Address in a HDWallet", "HDWalletGenerateAddressResponse", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Generate Address in a HDWallet", "HDWalletGenerateAddressResponse", $walletName, null, $output);
return $output;
<?php

// # Derive New Address in a HD Wallet
//
// This sample code demonstrate how you can derive new addresses in a hd wallet,
// as documented here at <a href="http://dev.blockcypher.com/#derive-address-in-wallet-endpoint">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/Wallet-Name/addresses/derive
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    /// Derive new address with subchain_index
    $params = array('subchain_index' => 1);
    $output = $walletClient->deriveAddress($walletName, $params);
} catch (Exception $ex) {
    ResultPrinter::printError("Derive Address in a HDWallet", "HDWallet", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Derive Address in a HDWallet", "HDWallet", $walletName, null, $output);
return $output;
示例#6
0
<?php

// # Create HDWallet
// This sample code demonstrate how you can create a HD wallet, as documented here at
// <a href="http://dev.blockcypher.com/#create-wallet-endpoint">docs</a>.
//
// API used: POST /v1/btc/main/wallets/hd
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default wallet name for samples
}
$wallet = new \BlockCypher\Api\HDWallet();
$wallet->setName($walletName);
$wallet->setExtendedPublicKey('xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8');
$wallet->setSubchainIndexes(array(1, 3));
/// For Sample Purposes Only.
$request = clone $wallet;
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    $output = $walletClient->create($wallet);
} catch (Exception $ex) {
    ResultPrinter::printError("Created HDWallet", "HDWallet", null, $request, $ex);
    exit(1);
}
ResultPrinter::printResult("Created HDWallet", "HDWallet", $output->getName(), $request, $output);
return $output;
<?php

// # Generate New Address in a HD Wallet
//
// This sample code demonstrate how you can generate new addresses in a hd wallet,
// as documented here at <a href="http://dev.blockcypher.com/#generate-address-in-wallet-endpoint">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/Wallet-Name/addresses/generate
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    /// Generate new address
    $output = $walletClient->generateAddress($walletName);
} catch (Exception $ex) {
    ResultPrinter::printError("Generate Address in a HDWallet", "HDWalletGenerateAddressResponse", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("Generate Address in a HDWallet", "HDWalletGenerateAddressResponse", $walletName, null, $output);
return $output;
<?php

// # Get All HD Wallet Addresses
//
// Use this call to list all the hd wallet addresses, as documented here at
// <a href="http://dev.blockcypher.com/#wallets">docs</a>
//
// API used: GET /v1/btc/main/wallets/hd/<Wallet-Name>/addresses?token=<Your-Token>
// In samples we are using CreateHDWallet.php sample to get the created instance of wallet.
// You have to run that sample before running this one or there will be no wallets
require __DIR__ . '/../bootstrap.php';
if (isset($_GET['wallet_name'])) {
    $walletName = filter_input(INPUT_GET, 'wallet_name', FILTER_SANITIZE_SPECIAL_CHARS);
} else {
    $walletName = 'bob';
    // Default hd wallet name for samples
}
$walletClient = new \BlockCypher\Client\HDWalletClient($apiContexts['BTC.main']);
try {
    $output = $walletClient->getWalletAddresses($walletName);
} catch (Exception $ex) {
    ResultPrinter::printError("List all HDWallet addresses", "AddressList", $walletName, null, $ex);
    exit(1);
}
ResultPrinter::printResult("List all HDWallet addresses", "AddressList", $walletName, null, $output);
return $output;