transaction-api\CreateAndSignAndSendTransaction.php
<?php

Create, Sign and Send Transaction

This sample code demonstrate how you can sign a transaction and send it to the network, as documented here at: http://dev.blockcypher.com/#creating-transactions

API used: POST /v1/btc/main/txs/new and POST /v1/btc/main/txs/send

Addresses used in this sample:

Source: n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4 Destination: mvwhcFDFjmbDWCwVJ73b8DcG6bso3CZXDj

Tx is created in sample CreateTransaction

/** @var \BlockCypher\Api\TXSkeleton $txSkeleton */ $txSkeleton = require 'CreateTransaction.php'; $txClient = new \BlockCypher\Client\TXClient($apiContexts['BTC.test3']);

Private key must have the same format as returned by Generate Address Endpoint: http://dev.blockcypher.com/?#generate-address-endpoint

$privateKeys = array( "1551558c3b75f46b71ec068f9e341bf35ee6df361f7b805deb487d8a4d5f055e" // Address: n3D2YXwvpoPg8FhcWpzJiS3SvKKGD8AXZ4 ); /// Sign TXSkeleton $txSkeleton = $txClient->sign($txSkeleton, $privateKeys); /// For sample purposes only. $request = clone $txSkeleton; try { /// Send TX to the network $txSkeleton = $txClient->send($txSkeleton); } catch (Exception $ex) { ResultPrinter::printError("Send Transaction", "TXSkeleton", null, $request, $ex); exit(1); } ResultPrinter::printResult("Send Transaction", "TXSkeleton", $txSkeleton->getTx()->getHash(), $request, $txSkeleton);