Example #1
1
/* This example script does the following:

   This script converts a given string into a Private Key for a specific address.
   Useful for extracting Private Keys in Wallet Import Format when using Distributed Trust,
   and mop-py to sweep coins out of the Distributed Trust address without going through Block.io.

   IMPORTANT! Specify your own API Key here.
   The network to use for the Wallet Import Format is determined from the API Key used.

   Contact support@block.io for any help with this.
*/

<?php 
require_once 'path/to/block_io.php';
/* Replace the $apiKey with the API Key from your Block.io Wallet. */
$apiKey = 'YOUR API KEY';
$pin = 'PIN - NOT NEEDED';
$version = 2;
// the API version
$block_io = new BlockIo($apiKey, $pin, $version);
$network = $block_io->get_balance()->data->network;
// get our current network off Block.io
$passphrase = strToHex('alpha1alpha2alpha3alpha4');
$key = $block_io->initKey()->fromPassphrase($passphrase);
echo "Current Network: " . $network . "\n";
echo "Private Key: " . $key->toWif($network) . "\n";
// print out the private key for the given network
Example #2
0
   IMPORTANT! Specify your own API Key and Secret PIN in this code. Keep your Secret PIN safe at all times.

   Contact support@block.io for any help with this.
*/

<?php 
require_once '/path/to/block_io.php';
/* Replace the $apiKey with the API Key from your Block.io Wallet. A different API key exists for Dogecoin, Dogecoin Testnet, Litecoin, Litecoin Testnet, etc. */
$apiKey = 'DogecoinTestnetAPIKey';
$pin = 'SecretPin';
$version = 2;
// the API version
$block_io = new BlockIo($apiKey, $pin, $version);
// create 4 keys for a 3 of 4 MultiSig address (1 key is Block.io's, added automatically by Block.io)
$passphrases = [strToHex('alpha1alpha2alpha3alpha4'), strToHex('alpha2alpha3alpha4alpha1'), strToHex('alpha3alpha4alpha1alpha2'), strToHex('alpha4alpha1alpha2alpha3')];
$keys = [$block_io->initKey()->fromPassphrase($passphrases[0]), $block_io->initKey()->fromPassphrase($passphrases[1]), $block_io->initKey()->fromPassphrase($passphrases[2]), $block_io->initKey()->fromPassphrase($passphrases[3])];
// create an address with label 'dTrust1' that requires 3 of 4 signatures from the above keys
$pubKeyStr = $keys[0]->getPublicKey() . "," . $keys[1]->getPublicKey() . "," . $keys[2]->getPublicKey() . "," . $keys[3]->getPublicKey();
$dTrustAddress = "";
echo "*** Creating Address with 4 Signers, and 3 Required Signatures: " . "\n";
try {
    $response = $block_io->get_new_dtrust_address(array('label' => 'dTrust1', 'public_keys' => $pubKeyStr, 'required_signatures' => 3));
    $dTrustAddress = $response->data->address;
} catch (Exception $e) {
    // print the exception below for debugging
    // echo "Exception: " . $e->getMessage() . "\n";
    // the label must exist, let's get its address then
    $dTrustAddress = $block_io->get_dtrust_address_by_label(array('label' => 'dTrust1'))->data->address;
}
echo "*** Address with Label=dTrust1: " . $dTrustAddress . "\n";
// let's deposit some testnet coins into this address