Jump to content

Quick question regarding the api I am using. It's giving me syntax error.


imgrooot

Recommended Posts

I am using this API https://github.com/blocktrail/blocktrail-sdk-php.

 

I am suppose to add this to top of my directory where I want to initialize the API. 

require 'vendor/autoload.php';
use Blocktrail\SDK\BlocktrailSDK;

But the second line gives me an error.

use Blocktrail\SDK\BlocktrailSDK;

Parse error: syntax error, unexpected 'use' (T_USE) in C:\xampp\htdocs\site\templates\header.php on line 12

Is the "use" a correct syntax for php? Why is it giving me an error?

Link to comment
Share on other sites

I actually did tried this on a test page outside of the normal site and it gives me this error. I'm pretty sure I installed it correctly using composer. 

Fatal error: Uncaught Blocktrail\SDK\Connection\Exceptions\ObjectNotFound: The object you've tried to access does not exist. in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php:336 Stack trace: #0 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(306): Blocktrail\SDK\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(173): Blocktrail\SDK\Connection\RestClient->request('GET', 'address/1NcXPMR...', NULL, NULL, NULL, NULL, NULL) #2 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\BlocktrailSDK.php(162): Blocktrail\SDK\Connection\RestClient->get('address/1NcXPMR...') #3 C:\xampp\htdocs\gift\test.php(28): Blocktrail\SDK\BlocktrailSDK->address('1NcXPMRaanz43b1...') #4 {main} thrown in C:\xampp\htdocs\site\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php on line 336
Link to comment
Share on other sites

Dude. The syntax error isn't in line 12, it's in one of the lines before that. If you want help with a syntax problem, then we need to actually see the exact code, not an “and so on” placeholder. Is this really so hard to understand?

 

Anyway, apparently you've repaired your secret code now. The new error is an interal library exception. Read the source code to understand why it's happening.

Link to comment
Share on other sites

Dude. The syntax error isn't in line 12, it's in one of the lines before that. If you want help with a syntax problem, then we need to actually see the exact code, not an “and so on” placeholder. Is this really so hard to understand?

 

Anyway, apparently you've repaired your secret code now. The new error is an interal library exception. Read the source code to understand why it's happening.

 

The error says invalid credentials, I assume it means my API key.  I double checked it and it's the correct key.

 

I am testing it on a test.php page with this code .

require_once 'composer/vendor/autoload.php';

use \Blocktrail\SDK\BlocktrailSDK;
$client = new BlocktrailSDK("0012a34a76bf10cf01c53d0c6059fc84a22f8e9d", "22250773dfde8f4ed0a0252a299549e9c024b132", "BTC", true /* testnet */);

$address = $client->address('1NcXPMRaanz43b1kokpPuYDdk6GGDvxT2T');
$latestBlock = $client->blockLatest();

var_dump($address['balance'], $latestBlock['hash']);

And this is the error i receive.

Fatal error: Uncaught Blocktrail\SDK\Connection\Exceptions\ObjectNotFound: The object you've tried to access does not exist. in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php:336 Stack trace: #0 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(306): Blocktrail\SDK\Connection\RestClient->responseHandler(Object(GuzzleHttp\Psr7\Response)) #1 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php(173): Blocktrail\SDK\Connection\RestClient->request('GET', 'address/1NcXPMR...', NULL, NULL, NULL, NULL, NULL) #2 C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\BlocktrailSDK.php(162): Blocktrail\SDK\Connection\RestClient->get('address/1NcXPMR...') #3 C:\xampp\htdocs\gift\test.php(7): Blocktrail\SDK\BlocktrailSDK->address('1NcXPMRaanz43b1...') #4 {main} thrown in C:\xampp\htdocs\gift\composer\vendor\blocktrail\blocktrail-sdk\src\Connection\RestClient.php on line 336
Link to comment
Share on other sites

Alright so I figured out why it was giving me that error. 

 

The reason I was getting the above error was because the wallet address I had in the call was EMPTY. It had no transactions sent or received so it was returning the default error.  All I have to do now is set up my own custom error if the wallet is empty.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.