<?php // Run on console: // php -f .\sample\transaction-api\NewTransactionEndpoint.php require __DIR__ . '/../bootstrap.php'; use BlockCypher\Api\TX; use BlockCypher\Auth\SimpleTokenCredential; use BlockCypher\Client\TXClient; use BlockCypher\Rest\ApiContext; $apiContext = ApiContext::create('test', 'bcy', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG')); // Create a new instance of TX object $tx = new TX(); // Tx inputs $input = new \BlockCypher\Api\TXInput(); $input->addAddress("C5vqMGme4FThKnCY44gx1PLgWr86uxRbDm"); $tx->addInput($input); // Tx outputs $output = new \BlockCypher\Api\TXOutput(); $output->addAddress("C4MYFr4EAdqEeUKxTnPUF3d3whWcPMz1Fi"); $tx->addOutput($output); // Tx amount $output->setValue(1000); // Satoshis // For Sample Purposes Only. $request = clone $tx; $txClient = new TXClient($apiContext); $txSkeleton = $txClient->create($tx); ResultPrinter::printResult("New TX Endpoint", "TXSkeleton", $txSkeleton->getTx()->getHash(), $request, $txSkeleton);
<?php // # Create TX To Fund Multisig Address // // This sample code demonstrate how you can create a new transaction, as documented here at: // <a href="http://dev.blockcypher.com/#creating-transactions">http://dev.blockcypher.com/#creating-transactions</a> // Destination address is a multisig address. // // API used: POST /v1/btc/main/txs/new require __DIR__ . '/../bootstrap.php'; // To use BlockCypher’s two-endpoint transaction creation tool, first you need to provide the input address(es), // output address, and value to transfer (in satoshis). This is provided in the form of a partially-filled out TX request object /// Tx inputs $input = new \BlockCypher\Api\TXInput(); $input->addAddress("n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4"); /// Tx outputs $output = new \BlockCypher\Api\TXOutput(); $output->setAddresses(array("03798be8162d7d6bc5c4e3b236100fcc0dfee899130f84c97d3a49faf83450fd81", "03dd9f1d4a39951013b4305bf61887ada66439ab84a9a2f8aca9dc736041f815f1", "03c8e6e99c1d0b42120d5cf40c963e5e8048fd2d2a184758784a041a9d101f1f02")); $output->setScriptType("multisig-2-of-3"); $output->setValue(1000); // Satoshis /// Tx $tx = new \BlockCypher\Api\TX(); $tx->addInput($input); $tx->addOutput($output); /// For Sample Purposes Only. $request = clone $tx; $txClient = new \BlockCypher\Client\TXClient($apiContexts['BTC.test3']); try { $txSkeleton = $txClient->create($tx); } catch (Exception $ex) {