/**
  * @return TXInput
  */
 public function build()
 {
     $txInput = new TXInput();
     $txInput->setAddresses($this->addresses);
     $txInput->setScriptType($this->scryptType);
     return $txInput;
 }
 /**
  * @param string $walletName
  * @param string $coinSymbol
  * @param string $token
  * @param string $payToAddress
  * @param int $amount
  * @return TXSkeleton
  */
 public function create($walletName, $coinSymbol, $token, $payToAddress, $amount)
 {
     $apiContext = $this->apiContextFactory->getApiContext($coinSymbol, $token);
     $txClient = new TXClient($apiContext);
     // DEBUG
     //var_dump($amount);
     //die();
     $tx = new TX();
     // Tx inputs
     $input = new TXInput();
     $input->setWalletName($walletName);
     $input->setWalletToken($token);
     $tx->addInput($input);
     // Tx outputs
     $output = new TXOutput();
     $output->addAddress($payToAddress);
     $tx->addOutput($output);
     // Tx amount
     $output->setValue($amount);
     // Satoshis
     try {
         $txSkeleton = $txClient->create($tx);
     } catch (BlockCypherConnectionException $e) {
         $data = $e->getData();
         //DEBUG
         //var_export($data);
         //die();
         $txSkeleton = new TXSkeleton($data);
         //DEBUG
         //var_dump($txSkeleton);
         //die();
         throw new InvalidTransaction($txSkeleton->getAllErrorMessages());
     }
     return $txSkeleton;
 }
 /**
  * @depends testSerializationDeserialization
  * @param TXInput $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getPrevHash(), "c719e0c52f63d9afbb72b00324499c0510672fa63c205db982188161ee3f105c");
     $this->assertEquals($obj->getOutputIndex(), 0);
     $this->assertEquals($obj->getScript(), "4830450221008627dbea1b070e8ceb025ab0ecb154227a65a34e6e8cd64966f181ca151d354f022066264b1930ad9e638f2853db683f5f81059e8c547bf9b4512046d2525c170c0b01210274cb62e999bdf96c9b4ef8a2b44c1ac54d9de879e2ee666fdbbf0e1a03090cdf");
     $this->assertEquals($obj->getOutputValue(), 50000);
     $this->assertEquals($obj->getAge(), 5197);
     $this->assertEquals($obj->getSequence(), 4294967295);
     $this->assertEquals($obj->getAddresses(), array("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4"));
     $this->assertEquals($obj->getScriptType(), "pay-to-pubkey-hash");
     // Only present in request body when wallet is used instead of an address.
     // See http://dev.blockcypher.com/#creating-transactions
     $this->assertEquals($obj->getWalletName(), "alice");
     $this->assertEquals($obj->getWalletToken(), "c0afcccdde5081d6429de37d16166ead");
     $this->assertEquals($obj->getError(), "message");
     $this->assertEquals($obj->getErrors(), array());
 }
<?php

// Run on console:
// php -f .\sample\transaction-api\CreateTransactionToFundMultisigAddressEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\TX;
use BlockCypher\Api\TXInput;
use BlockCypher\Api\TXOutput;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\TXClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('test3', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$input = new TXInput();
$input->addAddress("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4");
$output = new TXOutput();
$output->setAddresses(array("03798be8162d7d6bc5c4e3b236100fcc0dfee899130f84c97d3a49faf83450fd81", "03dd9f1d4a39951013b4305bf61887ada66439ab84a9a2f8aca9dc736041f815f1", "03c8e6e99c1d0b42120d5cf40c963e5e8048fd2d2a184758784a041a9d101f1f02"));
$output->setScriptType("multisig-2-of-3");
$output->setValue(1000);
// Satoshis
$tx = new TX();
$tx->addInput($input);
$tx->addOutput($output);
$txClient = new TXClient($apiContext);
$txSkeleton = $txClient->create($tx);
ResultPrinter::printResult("Created Multisig TX", "TXSkeleton", $txSkeleton->getTx()->getHash(), $tx, $txSkeleton);
<?php

// Run on console:
// php -f .\sample\transaction-api\CreateTxToFundMultisigAddrEndpoint.php
// You can also use builders, see CreateTxToFundMultisigAddrWithBuilderEndpoint.php sample
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Api\TX;
use BlockCypher\Api\TXInput;
use BlockCypher\Api\TXOutput;
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Client\TXClient;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('test3', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$input = new TXInput();
$output = new TXOutput();
$tx = new TX();
$tx->setInputs(array($input->addAddress("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4")))->setOutputs(array($output->setAddresses(array("03798be8162d7d6bc5c4e3b236100fcc0dfee899130f84c97d3a49faf83450fd81", "03dd9f1d4a39951013b4305bf61887ada66439ab84a9a2f8aca9dc736041f815f1", "03c8e6e99c1d0b42120d5cf40c963e5e8048fd2d2a184758784a041a9d101f1f02"))->setScriptType("multisig-2-of-3")->setValue(1000)));
$txClient = new TXClient($apiContext);
$txSkeleton = $txClient->create($tx);
ResultPrinter::printResult("Created Multisig TX", "TXSkeleton", $txSkeleton->getTx()->getHash(), $tx, $txSkeleton);