Blockcypher API code error

0 votes

I have the following code:

public static function test(){

    try{

        $apiContext = ApiContext::create(

            'test', 'bcy', 'v1',

            new SimpleTokenCredential('my_token'),

            array(       'mode' => 'sandbox','log.LogEnabled' => false, 'log.FileName' => 'BlockCypher.log',   'log.LogLevel' => 'DEBUG') );

        $input = new \BlockCypher\Api\TXInput();

        $input->addAddress("input_address");


        $output = new \BlockCypher\Api\TXOutput();

        $output->addAddress("output_address ");

        $output->setValue(1000); // Satoshis


        /// Tx

        $tx = new \BlockCypher\Api\TX();

        $tx->addInput($input);

        $tx->addOutput($output);


        $request = clone $tx;


        $txClient = new TXClient($apiContext);


        try {

            $output = $txClient->create($tx);

        } catch (Exception $ex) {

            dd("Created TX", "TXSkeleton", null, $request, $ex);

            exit(1);

        }

        dd("Created TX", "TXSkeleton", $output->getTx()->getHash(), $request, $output);


        return $output;

    }


    catch (\BlockCypher\Exception\BlockCypherConnectionException $ex) {

        echo $ex->getData();

        die;

    }


}

it gives error for checking url get/post

The response I get is as follows:

{

  "errors":[

    {

      "error":"Unable to find a transaction to spend for address CCrB7dvBT1bqNfWxupKPH9v8yN7xukmqUF."

    },

    {

      "error":"Error building transaction: Address 33cjwDAyNeAPVUMWqh9hdRxdmwdTE4kyTx is of unknown size.."

    },

    {

      "error":"Not enough funds after fees in 0 inputs to pay for 0 outputs, missing -22200."

    },

    {

      "error":"Error validating generated transaction: Transaction missing input or output."

    }

  ],

  "tx":{

    "block_height":-1,

    "block_index":-1,

    "hash":"d21633ba23f70118185227be58a63527675641ad37967e2aa461559f577aec43",

    "addresses":[

    ],

    "total":0,

    "fees":0,

    "size":10,

    "preference":"low",

    "relayed_by":"116.193.163.150",

    "received":"2017-11-14T10:20:43.757719705Z",

    "ver":1,

    "double_spend":false,

    "vin_sz":0,

    "vout_sz":0,

    "confirmations":0,

    "inputs":[

    ],

    "outputs":[

    ]

  }

}
Aug 23, 2018 in Blockchain by digger
• 26,740 points
1,227 views

1 answer to this question.

0 votes

This code will work:

<?php

try

    {

    $apiContext = ApiContext::create(env('BlockCypher_net') , env('BlockCypher_cn') , env('BlockCypher_v') , new SimpleTokenCredential(env('BlockCypher_key')) , array(

        'log.LogEnabled' => true,

        'log.FileName' => 'BlockCypher.log',

        'mode' => 'sandbox',

        'log.LogLevel' => 'DEBUG'

    ));

    $input = new BlockCypherApiTXInput();

    $input->addAddress($user['address']);

    $output = new BlockCypherApiTXOutput();

    $output->addAddress($data['address12']);

    $value_btc = 100000000 * ($data['btc12'] + 1 * ($data['btc12'] / 100));


    // dd($value_btc);


    $output->setValue($value_btc);

    $tx = new BlockCypherApiTX();

    $tx->addInput($input);

    $tx->addOutput($output);

    $request = clone $tx;

    $params = array(

        'includeToSignTx' => 1,

        'script_type' => 'mutlisig-n-of-m',

    );

    $txClient = new TXClient($apiContext);

    try

        {

        $txSkeleton = $txClient->create($tx, $params);

        $privateKeys = array(

            $user['private']

        );

        $txSkeleton = $txClient->sign($txSkeleton, $privateKeys);

        $txSkeleton = $txClient->send($txSkeleton);

        return array(

            'success' => 0

        );


        // dd($txSkeleton->getTx()->getHash());


        }


    catch(BlockCypherExceptionBlockCypherConnectionException $ex)

        {

        return array(

            'success' => 0,

            'msg' => $ex->getData()

        );

        }


    return $txSkeleton->getTx()->getHash();

    }


catch(BlockCypherExceptionBlockCypherConnectionException $ex)

    {

    return array(

        'success' => 0,

        'msg' => $ex->getData()

    );

    }
answered Aug 23, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

Send Payment error in Blockchain API

The following code should help: $address = null; try ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
1,754 views
0 votes
1 answer
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,428 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
0 votes
1 answer

How to solve Yobit API connection 503 server error?

Try to use "https://www.yobit.net/api/3/info" URL Instead of ...READ MORE

answered Aug 21, 2018 in Blockchain by slayer
• 29,370 points
823 views
0 votes
1 answer

Bitaps.com Error Code 10

Mistake in word qouta. Need quota $rules = [ ...READ MORE

answered Sep 7, 2018 in Blockchain by slayer
• 29,370 points
767 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP